# Automate certificate lifecycle for load
balancers

Learn how to use Certificate Manager (2nd gen) to automate the lifecycle of a
Google-managed certificate for a global Application Load Balancer.

## Before you begin

<br />

1. You need an existing Application Load Balancer with at least one target HTTPS proxy. For more information, see [Choose a load balancer](https://docs.cloud.google.com/load-balancing/docs/choosing-load-balancer).

### Required roles


To get the permissions that
you need to configure lifecycle management,

ask your administrator to grant you the
following IAM roles on your project:

- [Certificate Manager Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/certificatemanager#certificatemanager.editor) (`roles/certificatemanager.editor`)
- [Load Balancer Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/compute#compute.loadBalancerAdmin) (`roles/compute.loadBalancerAdmin`)


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).


These predefined roles contain

the permissions required to configure lifecycle management. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to configure lifecycle management:

- `compute.targetHttpsProxies.update`
- `compute.targetSslProxies.update`
- `compute.targetHttpsProxies.setCertificateMap`
- `compute.targetSslProxies.setCertificateMap`
- `compute.sslCertificates.*`


You might also be able to get
these permissions
with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or
other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## Configure certificate lifecycle management

To configure lifecycle management for your load balancer certificate:

1. In the Google Cloud console, go to **Certificate Manager (2nd gen)**.


   [Go to Certificate Manager (2nd gen)](https://console.cloud.google.com/security/ccm/overview)

   <br />

2. In the navigation menu, click **Manage Lifecycle**.

3. Click the **Load balancing** tab. A list of your load balancers appears.

4. Expand the load balancer row to see the attached certificates.

5. Click the name of the **target proxy**.

6. Click **Configure lifecycle management**. The page displays a list of
   associated certificates that you can add to and remove from.

7. Click **Certificate** and then click **Add certificate**.

8. Select an existing certificate or create a new certificate.

9. Enter the following details for the new certificate:

   - **Name:** Enter a unique name (for example, `my-lb-cert`).
   - **Scope:** Select the appropriate key distribution scope (for example, `Default`).
   - **Certificate type:** Select Self-managed or Google-managed certificates. For more information, see [certificate types](https://docs.cloud.google.com/load-balancing/docs/ssl-certificates#certificate-types).
   - **Domain Name:** Enter the domain name that this certificate covers (for example, `app.example.com`). This domain must be one that you control.
   - **Issuance Configuration:** Select your existing issuance configuration from the list. This configuration dictates the certificate authority, lifetime, and key type.
10. Click **Create**. The console adds the new certificate to the list for the
    target proxy.

11. Review the list of certificates, and then click **Update** to apply the
    changes to the target proxy.

### Verify the configuration

To verify the certificate configuration:

1. Check the certificate status. Issuance and provisioning can take
   from several minutes to a few hours. The certificate starts with a **Pending** status.

2. Monitor the certificate status on the **Certificates** tab within
   Certificate Manager (2nd gen). When the status is **Active**, the certificate is
   ready.

3. Ensure your domain's DNS records point to the load balancer IP address.

4. Test the setup by accessing your service using HTTPS (for example, `https://app.example.com`).

## Clean up


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

1. **Remove the certificate from the target proxy:**

   1. Go to the **Manage Lifecycle \> Load balancing** tab for your target proxy.
   2. Find the certificate that you created (`my-lb-cert`).
   3. Remove the certificate from the list.
   4. Click **Update**.
2. **Delete the certificate resource:**

   1. Go to the **Certificates** tab in Certificate Manager (2nd gen).
   2. Select the certificate (`my-lb-cert`).
   3. Click **Delete**.

You don't need to delete the load balancer, target proxy, or certificate issuance
configuration that you created or used in this quickstart.

## What's next

- [Compare Certificate Manager versions](https://docs.cloud.google.com/certificate-manager/docs/v2/comparison)
- [How Certificate Manager (2nd gen) works](https://docs.cloud.google.com/certificate-manager/docs/v2/core-components)
- [Issue a certificate using CA Service and verify in Certificate Manager (2nd gen)](https://docs.cloud.google.com/certificate-manager/docs/v2/quickstart-ca-service)
- [View certificate inventory](https://docs.cloud.google.com/certificate-manager/docs/v2/inventory)
- [Create issuance configuration](https://docs.cloud.google.com/certificate-manager/docs/v2/issuance-configuration)