# Deploy a MySQL instance with App Lifecycle Manager

Learn how to deploy a Cloud SQL instance using App Lifecycle Manager.

## Before you begin

1. Grant the [App Lifecycle Manager
   service account](https://docs.cloud.google.com/saas-runtime/docs/overview#saas-runtime-sa) the required permissions:
   1. Navigate to **App Lifecycle Manager** \> **Overview**
      **Get started** .  

      [Go to Get started with App Lifecycle Manager](https://console.cloud.google.com/saas/overview/get-started)
   2. In the banner with the message **The required permissions for App Lifecycle Manager
      account haven't been granted** , click **Grant permissions**.

<br />

## Model your Cloud SQL offering using a composite template

In this section, you'll use App Lifecycle Manager to model a composite template
(`sql-quickstart-template`) consisting of a Cloud SQL instance using
Application Design Center.

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

   [Go to SaaS Offering](https://console.cloud.google.com/saas/saasOfferings)
2. Click **Create**.

3. In the **Name of the SaaS offering** field, type: `my-sql-quickstart-saas-offering`.

4. In the **Region** drop-down, select the regions:

   - `us-central1`
   - `us-east1`
   - `us-east5`

   Click **Ok**.
5. Click **Create** . It may take a few minutes to create `my-sql-quickstart-saas-offering`.

   The **SaaS offering details** page opens.
6. On the **SaaS offering details** page, click **Create new template**.

7. On the **Create a new composite template** page:

   1. In the **Template ID** box, enter `sql-quickstart-template`.
   2. Click **Create template**. App Lifecycle Manager will take a few minutes to
      create the composite template.

      When App Lifecycle Manager has created the template successfully, you'll
      see its details in the **Connected application template** section of the **SaaS
      offering details** page.
8. In the **Connected application template** section, go to **Manage template** \>
   **Configure in canvas**.

   App Design Center opens in the Google Cloud console window.
9. In the **Components** area, find and click the **Cloud SQL (My SQL)**
   template.

   A **Cloud SQL (My SQL)** component is added to the canvas.
10. Click **Continue** \> **Deploy at scale with App Lifecycle Manager**.

    App Lifecycle Manager opens in the Google Cloud console window.
11. In the **Connected application template** section, click **Update template
    revision**.

12. On the **Update template revision** page, select `r-2` in the **Revision**
    drop-down.

13. Click **Update** . The **Connected application template** section displays
    **Importing Application Template**.

    It may take a few minutes for App Lifecycle Manager to import the template
    revision. When the revision has finished importing, you'll see the list of
    unit kinds populated in the **Unit kinds** tab.

## Provision a Cloud SQL instance using App Lifecycle Manager

In this section, you'll create and provision a unit (`my-sql-quickstart-unit`)
with a Cloud SQL instance in the `us-central1` region.

1. On the **SaaS offering details** page of `my-sql-quickstart-saas-offering`, click **Provision**.

   A **Provision** page opens.
2. On the **Provision** page, select `us-central1` in the **Region** drop-down.

   Click **Add** to add a unit to your SaaS offering.
3. On the **Add unit to provision** panel:

   1. In the **Unit name** box, type `my-sql-quickstart-unit-1`.
   2. In the **Unit kind** drop-down, select the `sql-quickstart-template` unit kind.
   3. In the **Release** drop-down, select (`r-3`).
   4. In the **Service account** drop-down, select the service account you created in the [Before you begin](https://docs.cloud.google.com/saas-runtime/docs/deploy-vm#before-you-begin) section.
4. Click **Add tenant project variables**.

   1. Select your project to provision your resources.
5. In the **Other input variables** section of the **Add unit to provision**
   panel:

   1. Click the `sql-my-sql-1_database_version` drop-down.

      - In the **Variable value** box, type `MY_SQL_8_0`.

      Click **Done**.
   2. Click the `sql-my-sql-1_name` drop-down.

      - In the **Variable value** box, type `my-sql-db-1`.

      Click **Done**.
   3. Click the `sql-my-sql-1_project_id` drop-down.

      - In the **Variable value** box, type your project ID.

      Click **Done**.
   4. Click the `sql-my-sql-1_region` drop-down.

      - In the **Variable value** box, type `us-central1`.

      Click **Done**.

   Click **Add** . You'll see `my-sql-quickstart-unit-1` in the **Units to be
   provisioned** table.
6. Click **Provision** to provision the `my-sql-quickstart-unit-1` which will
   create a live Cloud SQL instance in your SaaS offering.

   It may take a few minutes for App Lifecycle Manager to provision
   `my-sql-quickstart-unit-1`.

   > [!NOTE]
   > **Note:** You can repeat this process for each of the regions you selected when creating the SaaS offering to deploy the Cloud SQL instance in multiple regions.

## View the deployed Cloud SQL instance

You have now used App Lifecycle Manager to deploy a Cloud SQL instance.

To view the Cloud SQL instance that you deployed in this quickstart:

1. In Google Cloud console, go to the **App Lifecycle Manager** \> **Units** \> **Unit details** page.

   [Go to Units](https://console.cloud.google.com/saas/units)
2. Click the name of your unit: `my-sql-quickstart-unit-1`.

3. On the **Unit details** page:

   1. See that the **State** is:

      - **Ready** if the Cloud SQL instance is provisioned.
      - **Provisioning** if the operation is still in progress.

## Clean up


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

### Delete the project

If you deployed the Cloud SQL instance in a new Google Cloud project, and if
you no longer need the project, then delete it by completing the following steps:

> [!CAUTION]
> **Caution:** If you delete a project, all the resources in the project are permanently deleted.

1. In the Google Cloud console, go to the **Manage resources** page.

   [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)
2. In the project list, select the project that you want to delete, and then click **Delete**.
3. At the prompt, type the project ID, and then click **Shut down**.

## What's next

- To understand more about App Lifecycle Manager, see [App Lifecycle Manager overview](https://docs.cloud.google.com/saas-runtime/docs/overview).
- To get started with App Lifecycle Manager, begin with [Create a SaaS offering](https://docs.cloud.google.com/saas-runtime/docs/create-saas-offering).
- To understand how service accounts are used and how to grant the required permissions for these accounts, see [App Lifecycle Manager service accounts](https://docs.cloud.google.com/saas-runtime/docs/overview#saas-runtime-sa).
- For the steps to update the release, see [Rollout a release](https://docs.cloud.google.com/saas-runtime/docs/update-saas-offering).