> [!WARNING]
>
> **Preview**
>
>
> This product or feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section
> of the [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA products and features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

This guide explains how to use App Lifecycle Manager tenants to organize your
deployed units and how to deploy resources into separate *tenant projects*
to isolate and manage your resources.

For an overview of tenants and tenant projects, see [Tenants and tenant projects](https://docs.cloud.google.com/saas-runtime/docs/tenants).

## Before you begin

Before you create tenant projects or resources:

1. Create a Terraform configuration, an Artifact Registry repository, and create an artifact containing your SaaS application in your producer project. See [deploy a service instance with App Lifecycle Manager](https://docs.cloud.google.com/saas-runtime/docs/deploy-vm) to learn how to set up a SaaS offering.
2. Enable the APIs required by App Lifecycle Manager.


   <br />

   **Roles required to enable APIs**


   To enable APIs, you need the `serviceusage.services.enable` permission. If you
   created the project, then you likely already have this permission through the
   Owner role (`roles/owner`). Otherwise, you can get this permission through the
   Service Usage Admin role (`roles/serviceusage.serviceUsageAdmin`).
   [Learn how to grant roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).

   [Enable the APIs](https://console.cloud.google.com/apis/enableflow?apiid=saasservicemgmt.googleapis.com,artifactregistry.googleapis.com,config.googleapis.com,developerconnect.googleapis.com,cloudbuild.googleapis.com,storage.googleapis.com)

   <br />

3. Verify that you have the necessary service accounts and Identity and Access Management roles
   granted *within the producer project* .
   This includes the user-created service account and the permissions granted
   to the `service-PROJECT-NUMBER@gcp-sa-saasservicemgmt.iam.gserviceaccount.com`
   account on the producer project.

## Set up a tenant project

When you provision your tenant's resources into separate projects, your
resources, IAM policies, quotas, and network configurations are
separated for each of your tenants, making it less likely for breaches or
misconfigurations with one tenant to affect your others.

You'll need:

- one producer project, and
- one tenant project for each of your tenants.

### Console

To set up tenant and producer projects using Google Cloud console:

1. [Create a producer project, and a tenant project for each of your tenants](https://console.cloud.google.com/home/dashboard).
2. [Enable billing on your tenant and producer projects](https://docs.cloud.google.com/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).
3. Enable the APIs required by App Lifecycle Manager in your tenant projects.


   <br />

   **Roles required to enable APIs**


   To enable APIs, you need the `serviceusage.services.enable` permission. If you
   created the project, then you likely already have this permission through the
   Owner role (`roles/owner`). Otherwise, you can get this permission through the
   Service Usage Admin role (`roles/serviceusage.serviceUsageAdmin`).
   [Learn how to grant roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).

   [Enable the APIs](https://console.cloud.google.com/apis/enableflow?apiid=saasservicemgmt.googleapis.com,artifactregistry.googleapis.com,config.googleapis.com,developerconnect.googleapis.com,cloudbuild.googleapis.com,storage.googleapis.com)

   <br />

4. Verify that your tenant projects have actuation service accounts with the
   required permissions.

   For details, see [App Lifecycle Manager service accounts](https://docs.cloud.google.com/saas-runtime/docs/overview#actuation-sa).

You've successfully set up your tenant and producer projects. Once you've
created and enabled billing for your producer and tenant projects, you can
create tenant resources and associate units with tenants.

### gcloud

To set up a producer and tenant projects using Google Cloud CLI:

1. Create your producer project, and a tenant project for each of your
   tenants:

       gcloud projects create PRODUCER_PROJECT_ID --name="SaaS producer project" [--folder=folder-id]
       gcloud projects create TENANT_PROJECT_ID --name="SaaS tenant A project" [--folder=folder-id]

   Replace:
   - `PRODUCER_PROJECT_ID`: A string identifier representing the producer project ID.
   - `TENANT_PROJECT_ID`: A string identifier representing the tenant project ID.
2. Enable billing for your tenant and producer projects:

        gcloud beta billing projects link PRODUCER_PROJECT_ID --billing-account=BILLING_ACCOUNT_ID
        gcloud beta billing projects link TENANT_PROJECT_ID --billing-account=BILLING_ACCOUNT_ID

   Replace:
   - `PRODUCER_PROJECT_ID`: A string identifier representing the producer project ID.
   - `TENANT_PROJECT_ID`: A string identifier representing the tenant project ID.
   - `BILLING_ACCOUNT_ID`: The ID of the billing account you want to associate with the specified project.

   > [!NOTE]
   > **Note:** You need to link each tenant project with a `gcloud beta billing
   > projects link` command.

3. Grant the actuation service account the necessary Identity and Access Management roles for
   each tenant project:

        gcloud projects add-iam-policy-binding TENANT_PROJECT_ID \
        --member='serviceAccount:SERVICE_ACCOUNT@PRODUCER_PROJECT_ID.iam.gserviceaccount.com' \
        --role=ROLE

   Replace:
   - `TENANT_PROJECT_ID`: A string identifier representing the tenant project ID.
   - `PRODUCER_PROJECT_ID`: A string identifier representing the producer project ID.
   - `SERVICE_ACCOUNT`: The service account you want to grant roles to within the specified project.
   - `ROLE`: The Identity and Access Management role to grant.

     You'll need to run `gcloud projects add-iam-policy-binding` for each
     role you want to grant to the specified service account (`--role='roles/compute.admin'`,
     for example).

You've successfully set-up your tenant and producer projects. Once you've
created and enabled billing for your producer and tenant projects, you can
create tenant resources and associate units with tenants.

## Create a tenant resource

Create a *tenant* resource in your SaaS offering to represent your customer:

1. In Google Cloud console, go to to **App Lifecycle Manager** \> **Tenants**.

   [Go to Tenants](https://console.cloud.google.com/saas/tenants)
2. Click **Create**.

3. In the **Tenant name** box, enter a name for your tenant resource.

4. Optional: In the **Customer resource** box, provide a consumer resource with
   consumer-defined settings for integration.

5. In the **SaaS offering** box, select the SaaS offering you want to
   associate your tenant with.

6. In the **Region** drop-down, select a region where tenant metadata will
   be stored.

7. Optional: Click **Add label** to add a key-value pair label to your tenant.

8. Click **Create** to create your tenant resource.

You have successfully created a tenant resource.

## Associate a unit with a tenant

After you create a tenant and deploy a unit, you can link them to each other.
This association primarily serves as an organizational tag that helps you
organize which units belong to which tenant.

For more information about deploying units, see [Deploy a VM with App Lifecycle Manager](https://docs.cloud.google.com/saas-runtime/docs/deploy-vm).

To associate a unit with a tenant:

1. In Google Cloud console, go to **App Lifecycle Manager** \> **Tenants**.

   [Go to Tenants](https://console.cloud.google.com/saas/tenants)
2. Click the name of the tenant you want to associate to a unit.

3. Click **Edit**.

4. In the **Associated units** section, click **Add Unit**.

5. Select the units you want to associate with this tenant.

6. Click **Done**.

7. Click **Save**.

The selected units are associated with the indicated tenant.

## Provision a new unit with tenant project variables

When you provision a unit associated with a tenant, you must provide the `tenant_project_id`
variable.

1. Navigate to **App Lifecycle Manager** \> **Units** in the Google Cloud console.

   [Go to Units](https://console.cloud.google.com/saas/units)
2. Create a new unit associated with your unit kind.

3. Click **Provision**.

4. Select the **Release** to provision to your tenant unit.

5. Select the **Actuation service account** you granted permissions to in your
   tenant project. You should follow the principle of least privilege and grant
   only the necessary roles for the resources being managed.

6. In the **Input Variables** section:

   1. Verify that the `tenant_project_id` variable listed as you defined it in your Terraform configuration `variables.tf` file.
   2. In the **Tenant Project ID** box, provide the name of your tenant project.
   3. Provide input variables defined in your Terraform configuration. If you haven't defined other variables in your Terraform configuration, skip this step.
7. Click **Provision**.

App Lifecycle Manager triggers Infrastructure Manager using the specified
actuation service account. Infrastructure Manager reads the `tenant_project_id`
variable and creates the VM *inside that tenant project*.

> [!NOTE]
> **Note:** If provisioning fails, verify the required APIs are enabled and your permissions are correctly configured.

## Re-provision a unit with a new release

When you re-provision an existing unit with a new release, you must provide
the `tenant_project_id` variable.

1. Navigate to **App Lifecycle Manager** \> **Units** in the Google Cloud console.

   [Go to Units](https://console.cloud.google.com/saas/units)
2. Select the unit associated with your unit kind.

3. Click **Edit Provisioning**.

4. Select the **Release** you created with the updated Terraform configuration.

5. Select the **Actuation service account** you granted permissions to in your
   tenant project. You should follow the principle of least privilege and grant
   only the necessary roles for the resources being managed.

6. In the **Input Variables** section:

   1. Verify that the `tenant_project_id` variable listed as you defined it in your Terraform configuration `variables.tf` file.
   2. In the **Tenant Project ID** box, provide the name of your tenant project.
   3. Provide input variables defined in your Terraform configuration. If you haven't defined other variables in your Terraform configuration, skip this step.
7. Click **Update**.

App Lifecycle Manager triggers Infrastructure Manager using the specified
actuation service account. Infrastructure Manager reads the `tenant_project_id`
variable and creates the VM *inside that tenant project*.

> [!NOTE]
> **Note:** If provisioning fails, verify that the required APIs are enabled and your permissions are correctly configured.

## What's next

- Explore [managing dependencies between units](https://docs.cloud.google.com/saas-runtime/docs/dependencies).
- Learn more about [using variables and variable mapping](https://docs.cloud.google.com/saas-runtime/docs/variables).
- Review [permissions required for service accounts](https://docs.cloud.google.com/saas-runtime/docs/overview#actuation-sa).