When you [preview and deploy
applications](https://docs.cloud.google.com/application-design-center/docs/deploy-applications), you can use
an existing [service account](https://docs.cloud.google.com/iam/docs/service-account-overview.md.txt), or
Application Design Center can automatically create a service account.

To deploy applications using your own service account, you must grant the
necessary Identity and Access Management roles and permissions, including the following:

- Add IAM policy bindings to the service account and user account.
- Grant the service account the [roles](https://docs.cloud.google.com/iam/docs/roles-overview.md.txt) required to deploy each resource.
- Add permissions to the service account to deploy outside of the project where the service account was created.
- Update your organization policies to let you create a service account in one project and use it to deploy resources in another project.

## Configure your service account

To configure your service account, do the following:

1. Grant the
   [Service Account User role](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser)
   (`roles/iam.serviceAccountUser`) on your service account to the
   App Design Center service agent of the management project:

   ```bash
   gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_EMAIL \
       --member="serviceAccount:service-MANAGEMENT_PROJECT_NUMBER@gcp-sa-designcenter.iam.gserviceaccount.com" \
       --role="roles/iam.serviceAccountUser"
   ```

   Replace the following:
   - `SERVICE_ACCOUNT_EMAIL`: Your service account email, such as `my-service-account@SERVICE_ACCOUNT_PROJECT_ID.iam.gserviceaccount.com`.
   - `SERVICE_ACCOUNT_PROJECT_ID`: The project ID of the project that contains your service account.
   - `MANAGEMENT_PROJECT_NUMBER`: The project number of the [management project](https://docs.cloud.google.com/application-design-center/docs/key-concepts.md.txt#mgmt-project) that contains your space.
2. Grant the `roles/iam.serviceAccountUser` role on your service account to
   the user who deploys the application:

   ```bash
   gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_EMAIL \
       --member="user:USER_EMAIL" \
       --role="roles/iam.serviceAccountUser"
   ```

   Replace the following:
   - `SERVICE_ACCOUNT_EMAIL`: Your service account email, such as `my-service-account@SERVICE_ACCOUNT_PROJECT_ID.iam.gserviceaccount.com`.
   - `USER_EMAIL`: The email address of the user who performs the deployment.
3. On the
   [management project](https://docs.cloud.google.com/application-design-center/docs/key-concepts.md.txt#mgmt-project)
   that contains your space, grant the App Hub Editor (`roles/apphub.editor`)
   and Cloud Infrastructure Manager Agent (`roles/config.agent`) roles to your
   service account:

   ```bash
   gcloud projects add-iam-policy-binding MANAGEMENT_PROJECT_ID \
       --member="serviceAccount:SERVICE_ACCOUNT_EMAIL" \
       --role="roles/apphub.editor"
   ```

   ```bash
   gcloud projects add-iam-policy-binding MANAGEMENT_PROJECT_ID \
       --member="serviceAccount:SERVICE_ACCOUNT_EMAIL" \
       --role="roles/config.agent"
   ```

   Replace the following:
   - `MANAGEMENT_PROJECT_ID`: The project ID of the management project that contains your space.
   - `SERVICE_ACCOUNT_EMAIL`: Your service account email, such as `my-service-account@SERVICE_ACCOUNT_PROJECT_ID.iam.gserviceaccount.com`.
4. In the project that contains your service account, make sure that the
   `iam.disableCrossProjectServiceAccountUsage` organization policy constraint
   isn't enforced. This constraint is enforced by default.

   Disable enforcement of the organization policy constraint:

   ```bash
   gcloud resource-manager org-policies disable-enforce \
       iam.disableCrossProjectServiceAccountUsage \
       --project=SERVICE_ACCOUNT_PROJECT_ID
   ```

   Replace `SERVICE_ACCOUNT_PROJECT_ID` with the project
   ID of the project that contains your service account.
5. On the deployment project where you're deploying resources, grant your
   service account the Service Usage Admin role
   (`roles/serviceusage.serviceUsageAdmin`) and the roles required to deploy
   those resources. App Design Center displays the required
   roles in the Google Cloud console when you
   [deploy applications](https://docs.cloud.google.com/application-design-center/docs/deploy-applications.md.txt).

   For example, grant the `roles/serviceusage.serviceUsageAdmin` role and the
   Cloud Run Admin role (`roles/run.admin`) to your service account on the
   deployment project:

   ```bash
   gcloud projects add-iam-policy-binding DEPLOYMENT_PROJECT_ID \
       --member="serviceAccount:SERVICE_ACCOUNT_EMAIL" \
       --role="roles/serviceusage.serviceUsageAdmin"
   ```

   ```bash
   gcloud projects add-iam-policy-binding DEPLOYMENT_PROJECT_ID \
       --member="serviceAccount:SERVICE_ACCOUNT_EMAIL" \
       --role="roles/run.admin"
   ```

   Replace the following:
   - `DEPLOYMENT_PROJECT_ID`: The project ID of the project where you're deploying resources.
   - `SERVICE_ACCOUNT_EMAIL`: Your service account email, such as `my-service-account@SERVICE_ACCOUNT_PROJECT_ID.iam.gserviceaccount.com`.
6. App Design Center uses Infrastructure Manager to deploy
   applications in the console. To use your own service
   account to deploy with Infra Manager, complete the steps in
   [Grant access across multiple projects](https://docs.cloud.google.com/infrastructure-manager/docs/configure-service-account.md.txt#grant_access_across_multiple_projects).

7. Optional: If the application that you're deploying contains private
   components that you imported through a Developer Connect
   connection, grant your service account the Service Account Token Creator
   role (`roles/iam.serviceAccountTokenCreator`) on the project that contains
   your service account:

   ```bash
   gcloud projects add-iam-policy-binding SERVICE_ACCOUNT_PROJECT_ID \
       --member="serviceAccount:SERVICE_ACCOUNT_EMAIL" \
       --role="roles/iam.serviceAccountTokenCreator"
   ```

   Replace the following:
   - `SERVICE_ACCOUNT_PROJECT_ID`: The project ID of the project that contains your service account.
   - `SERVICE_ACCOUNT_EMAIL`: Your service account email, such as `my-service-account@SERVICE_ACCOUNT_PROJECT_ID.iam.gserviceaccount.com`.

## What's next

- Learn how to update, scale, and delete your resources by [managing applications](https://docs.cloud.google.com/application-design-center/docs/manage-applications.md.txt).
- Provision your infrastructure with the console or the command line by [deploying applications](https://docs.cloud.google.com/application-design-center/docs/deploy-applications.md.txt).