# Create a cluster by using a template

This page shows you how to use an inline
[Google APIs Explorer](https://developers.google.com/apis-explorer/#p/)
template to create a Managed Service for Apache Spark cluster.

For other ways to create a cluster, see:

- [Create a cluster by using the Google Cloud console](https://docs.cloud.google.com/managed-spark/docs/quickstarts/create-cluster-console.md.txt#create_a_cluster)
- [Create a cluster by using the Google Cloud CLI](https://docs.cloud.google.com/managed-spark/docs/quickstarts/create-cluster-gcloud.md.txt#create_a_cluster)
- [Create a cluster by using client libraries](https://docs.cloud.google.com/managed-spark/docs/quickstarts/create-cluster-client-libraries.md.txt)

## Before you begin

<br />

### Required roles

Certain IAM roles are required to
run the examples on this page. Depending on organization policies, these
roles may have already been granted. To check role grants, see
[Do you need to grant roles?](https://docs.cloud.google.com/managed-spark/docs/concepts/iam#do_you_need_to_grant_roles).

For more information about granting roles, see
[Manage access to projects,folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

#### User roles


To get the permissions that
you need to create a Managed Service for Apache Spark cluster,

ask your administrator to grant you the
following IAM roles:

- [Dataproc Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/dataproc.md.txt#dataproc.editor) (`roles/dataproc.editor`) on the project
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the Compute Engine default service account


#### Service account role


To ensure that the Compute Engine default service account has the necessary
permissions to create a Managed Service for Apache Spark cluster,

ask your administrator to grant the
[Dataproc Worker](https://docs.cloud.google.com/iam/docs/roles-permissions/dataproc.md.txt#dataproc.worker) (`roles/dataproc.worker`) IAM role to the Compute Engine default service account on the project.


**Important:** You must grant this role to the Compute Engine default service account, *not* to your user account. Failure to grant the role to the correct principal might result in permission errors.

<br />

## Create a cluster

Before you can run Managed Service for Apache Spark jobs, you need to create a cluster
of virtual machines to run them on. To create a Managed Service for Apache Spark cluster
in your project, fill in and execute the Google APIs Explorer **Try this Method**
template on this page (scroll or click **Try it!** to move to the template).

> [!NOTE]
> **Note:** The `region` and `clusterName` parameter values are filled in for you. Accept or replace these "seeded" parameter values.

1. **Request parameters:**

   1. Insert your [**projectId**](https://console.cloud.google.com/).
   2. Specify the [**region**](https://docs.cloud.google.com/compute/docs/regions-zones/regions-zones#available) where your cluster will be located (accept or replace "us-central1"). Since you are not specifying a zone within the region in this quickstart, [Managed Service for Apache Spark Auto Zone placement](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/auto-zone.md.txt) will pick a zone within the region where it will create the cluster.
2. **Request body:**

   1. Specify a [**clusterName**](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/projects.regions.clusters.md.txt#Cluster.FIELDS.cluster_name), (accept or replace "example-cluster"). You will use this name to interact with your cluster, for example when you [submit jobs](https://docs.cloud.google.com/managed-spark/docs/quickstarts/submit-spark-job-template.md.txt) or [update the cluster](https://docs.cloud.google.com/managed-spark/docs/quickstarts/update-cluster-template.md.txt).
3. Click **EXECUTE**. The first time you
   run the API template, you may be asked to choose and sign into
   your Google account, then authorize the Google APIs Explorer to access your
   account. If the request is successful, the JSON response
   shows that cluster creation is pending.

4. To confirm cluster creation, open the
   [Managed Service for Apache Spark Clusters](https://console.cloud.google.com/dataproc/clusters)
   page in the Google Cloud console. After cluster provisioning completes,
   the cluster's status will show as "Running".


## Clean up


To avoid incurring charges to your Google Cloud account for
the resources used on this page, follow these steps.

<br />

1. If you don't need the cluster to explore the other quickstarts or to run other jobs, use the [APIs Explorer](https://docs.cloud.google.com/managed-spark/docs/quickstarts/quickstart-explorer-delete.md.txt), the [Google Cloud console](https://docs.cloud.google.com/managed-spark/docs/quickstarts/create-cluster-console.md.txt#clean-up), the gcloud CLI [gcloud](https://docs.cloud.google.com/managed-spark/docs/quickstarts/create-cluster-gcloud.md.txt#clean-up) command-line tool, or the [Cloud Client Libraries](https://docs.cloud.google.com/managed-spark/docs/quickstarts/create-cluster-client-libraries.md.txt) to delete the cluster.

## What's next

- Learn how to [submit a Spark job by using a template](https://docs.cloud.google.com/managed-spark/docs/quickstarts/submit-spark-job-template.md.txt).