> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/installation.md).

# Installing LaunchDarkly

Install the P0 LaunchDarkly integration: create and store the access token, deploy the connector, and add each LaunchDarkly account.

{% hint style="info" %}
The LaunchDarkly integration is in preview. Functionality and configuration may change.
{% endhint %}

You install LaunchDarkly in two parts. A **LaunchDarkly connector** is P0's connector, deployed in your AWS account or Google Cloud project. A **LaunchDarkly account** is one LaunchDarkly account that a connector reaches, with its own access token and secret. Install a connector once, then add each account, either from the P0 app or with the P0 Terraform provider. For how the parts fit together, see [LaunchDarkly](https://docs.p0.dev/integrations/resource-integrations/launchdarkly.md#how-it-works).

The shell commands on this page are written for bash and zsh.

## Before you begin

You need:

* **A LaunchDarkly admin**, to create the access token. The token is that admin's own.
* **P0 installed in the cloud the connector runs in.** P0 invokes the connector through its IAM management there, and the connector reads each account's secret from that cloud's secret manager:

| The connector runs on | Install, for the connector's account or project                                                                               | The secret is in      | Install, for the secret's account or project                                                                             |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| AWS Lambda            | [AWS](https://docs.p0.dev/integrations/resource-integrations/aws.md#setting-up-aws-iam-management)                            | AWS Secrets Manager   | The [AWS Secrets Manager](https://docs.p0.dev/integrations/resource-integrations/aws-secrets-manager.md) integration     |
| Google Cloud Run      | [Google Cloud](https://docs.p0.dev/integrations/resource-integrations/google-cloud.md#install-iam-management-on-each-project) | Google Secret Manager | The [Google Secret Manager](https://docs.p0.dev/integrations/resource-integrations/google-secret-manager.md) integration |

* [**Terraform**](https://developer.hashicorp.com/terraform/install), to deploy the connector:
  * **AWS Lambda:** Terraform 1.4 or later, run on Linux or macOS with Docker running and the AWS CLI signed in to the connector's account. Lambda runs images only from Amazon ECR, so the connector's Terraform copies P0's image from Docker Hub into an ECR repository with a shell script. The apply fails on Windows, and on remote runs that have no Docker, such as HCP Terraform's.
  * **Google Cloud Run:** Terraform 1.2 or later, and the `hashicorp/google` provider 6.0.0 or later. Cloud Run pulls P0's image from Docker Hub itself, so you don't need Docker. The machine that runs Terraform still has to reach Docker Hub, because every plan reads the image's digest there. The [Service Usage API](https://console.cloud.google.com/apis/library/serviceusage.googleapis.com) must be enabled in the connector's project, because the connector's Terraform enables the IAM and Cloud Run APIs through it.
  * **Both:** the `kreuzwerker/docker` provider 3.3.0 or later, below 5.0. The connector's Terraform declares it in a `required_providers` block of its own. If your configuration already has a `required_providers` block, add the `docker` entry to it, at 3.3 or later, and delete the generated block: Terraform refuses a second one.

The secret can be in a different account or project from the connector, in the same cloud. On AWS, the connector and the secret must both be in commercial regions, not in GovCloud, China, ISO or European Sovereign Cloud regions.

P0 grants access only to people who already have a LaunchDarkly member. For what each requestor needs, see [Requesting LaunchDarkly access](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/requesting-access.md).

### Identity providers that manage LaunchDarkly

{% hint style="warning" %}
**If your identity provider manages LaunchDarkly members through SSO or SCIM, it can undo what P0 grants.** With SAML SSO or SCIM on, LaunchDarkly lets your identity provider override changes made to a member. A grant that the identity provider undoes right away fails, and P0 takes back what it applied. One undone later ends the person's access early. Before you install, check which member settings your identity provider manages, and request only access it leaves alone.
{% endhint %}

## Step 1: Create the access token

Have a LaunchDarkly admin create a personal access token with the Admin role, as in LaunchDarkly's [API access tokens](https://launchdarkly.com/docs/home/account/api) guide. Use an admin member set aside for P0 if you can, since the token can do anything that admin can. Create one token for each account, and use it for nothing else.

{% hint style="warning" %}
**The personal token stops working when its admin leaves LaunchDarkly.** P0 then can't grant or revoke anything on the account until you store another admin's token in the secret, as in [#rotate-the-access-token](#rotate-the-access-token "mention"). The token's admin can't receive access through P0 on the account either: P0 never changes the access of the member whose token it uses.
{% endhint %}

## Step 2: Store the access token

Store the token alone, with nothing around it, as the account's secret, in the secret manager of the connector's cloud. You choose the secret's name, and you enter it in P0 in [#step-4-add-the-launchdarkly-account](#step-4-add-the-launchdarkly-account "mention"). Each account has one secret.

Each command below reads the token without showing it. Run it, paste the token and press Enter. The command passes the token to the secret manager on its input and then clears it. Don't put the token in the command itself, where your shell history keeps it.

For Google Secret Manager, with `gcloud` signed in to an account that can create secrets in the project:

```bash
read -rs LD_TOKEN
printf %s "$LD_TOKEN" | gcloud secrets create launchdarkly-acme-prod-token \
  --project <project-id> \
  --data-file=-
unset LD_TOKEN
```

For AWS Secrets Manager, with the AWS CLI signed in to the secret's account:

```bash
read -rs LD_TOKEN
printf %s "$LD_TOKEN" | aws secretsmanager create-secret \
  --name launchdarkly/acme-prod/token \
  --secret-string file:///dev/stdin \
  --region <region>
unset LD_TOKEN
```

A secret's name follows its secret manager's rules:

| Secret manager        | Secret name                                        |
| --------------------- | -------------------------------------------------- |
| AWS Secrets Manager   | Up to 512 letters, digits and `/_+=.@-`            |
| Google Secret Manager | Up to 255 letters, digits, underscores and hyphens |

For a secret in a different AWS account from the connector, the name can't end in a hyphen and six characters, such as `-AbCdEf`: Secrets Manager can't find a secret in another account by such a name, and P0 refuses it. Use another name, or a secret in the connector's own account.

On AWS, a secret in a different account from the connector must be encrypted with a customer-managed KMS key, and both the secret's resource policy and the key's policy must allow the connector's role. Pass the key to `create-secret` with `--kms-key-id <kms-key-arn>`. The account's Terraform covers both policies, in [#step-4-add-the-launchdarkly-account](#step-4-add-the-launchdarkly-account "mention").

## Step 3: Install the connector

One connector can serve several LaunchDarkly accounts, so skip this step if you already have a connector that should reach the new account. Every account behind a connector shares that connector's email domain pattern (see [#the-email-domain-pattern](#the-email-domain-pattern "mention")).

{% hint style="warning" %}
**A connector's ID and where it runs can't change once you add it.** To move a connector, add a new one.
{% endhint %}

1. Open the P0 dashboard at [p0.app](https://p0.app) and log in to your organization.
2. In the sidebar, click **Integrations**. Under **Resources**, click **LaunchDarkly**.
3. Select the **LaunchDarkly connector** component, and add a connector.
4. Enter an **ID** for the connector, such as `prod`. Each LaunchDarkly account names its connector by this ID. Use lowercase letters, digits and hyphens, starting and ending with a letter or digit, up to 63 characters.
5. Under **Connector hosting**, choose **AWS Lambda** or **Google Cloud Run**, and fill in the fields:

| Hosting          | Field                | What to enter                                                                                                                                                                                                  |
| ---------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AWS Lambda       | **AWS account ID**   | The account the connector runs in. The list shows the accounts where P0's AWS IAM management is installed.                                                                                                     |
| AWS Lambda       | **Connector name**   | The Lambda function's name, which is also the name of the IAM role it runs as. Use 2 to 64 characters: lowercase letters, digits and single hyphens, starting with a letter and ending with a letter or digit. |
| AWS Lambda       | **Connector region** | An AWS region, such as `us-west-2`                                                                                                                                                                             |
| Google Cloud Run | **GCP project ID**   | The project the connector runs in. The list shows the projects where P0's Google Cloud IAM management is installed.                                                                                            |
| Google Cloud Run | **Connector name**   | The Cloud Run service's name, which is also the ID of the service account it runs as. Use 6 to 30 characters: lowercase letters, digits and hyphens, starting with a letter and ending with a letter or digit. |
| Google Cloud Run | **Connector region** | A Google Cloud region, such as `us-west1`                                                                                                                                                                      |

6. Continue to the connector's Terraform. P0 fills it in with the values you entered.
7. Add the Terraform to your configuration, set the email domain pattern variable it declares (see [#the-email-domain-pattern](#the-email-domain-pattern "mention")), and apply it.
8. Click **Next**. P0 checks that it can invoke the connector. IAM changes can take a few seconds to take effect, so if P0 is denied access right after you apply, wait and try again.

Keep your copy of the connector's Terraform. You change the email domain pattern and the connector's image in it later.

### The email domain pattern

The connector gives LaunchDarkly access only to people whose email domain matches a regular expression that you set. The connector's Terraform declares it as a required variable, and sets it on the connector as the `DOMAIN_ALLOW_PATTERN` environment variable. P0 never sends the pattern, and can't change it. Each account's page in P0 shows the pattern as **Allowed domains**: what the connector reported when the account was added, or when an admin last checked it from the installer. When you change the pattern, the page shows the old one until an admin checks the account again.

The variable's name ends in `_domain_allow_pattern` and carries the connector's ID, with each hyphen written as an underscore. For the connector `prod-eu` it's `p0_launchdarkly_connector_prod_eu_domain_allow_pattern`. Copy the name from the Terraform that P0 generated.

Write the pattern this way:

* **Match the whole domain.** The connector tests the pattern against the text after the `@`, and the pattern has to match all of it. Leave out the `@`, and leave out `^` and `$`: the connector anchors the pattern itself.
* **Write each dot as `[.]`.** A bare `.` matches any character, so `example.com` also allows `exampleXcom`. Write `example[.]com`.
* **Separate several domains with `|`**, as in `example[.]com|example[.]net`.
* **Name subdomains if you want them.** `example[.]com` doesn't match `mail.example.com`. To allow every subdomain too, use `([a-z0-9-]+[.])*example[.]com`.

Capitalization doesn't matter.

Set the variable in a `.tfvars` file:

```terraform
p0_launchdarkly_connector_prod_eu_domain_allow_pattern = "example[.]com"
```

To pass it on the command line instead, single-quote it so the shell leaves the brackets alone:

```bash
terraform apply -var 'p0_launchdarkly_connector_prod_eu_domain_allow_pattern=example[.]com'
```

While the pattern is unset, blank, or isn't a regular expression that compiles, the connector refuses every request, and P0 can't finish installing an account through it.

To change the pattern later, change the variable and apply again. The connector uses the new pattern from its next call. A person whose domain the new pattern no longer allows keeps the access they already have until it ends, and P0 still revokes it then.

### What the connector's Terraform creates on AWS

| Resource                                               | What it's for                                                                                                                                                                                             |
| ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| An ECR repository, named after the connector           | Holds the copy of P0's connector image, `p0security/p0-connector-launchdarkly`, that Lambda runs. Its tags can't be overwritten, so pushing to the repository can't replace the image the connector runs. |
| A CloudWatch log group, `/aws/lambda/<connector-name>` | The connector's logs, kept for 30 days. Change `log_retention_days` in the Terraform to keep them for longer or shorter.                                                                                  |
| An IAM role, named after the connector                 | The identity the connector runs as. The connector's Terraform lets it write its own logs. Each LaunchDarkly account's Terraform adds read access to that account's secret.                                |
| The Lambda function                                    | Runs the connector. It calls LaunchDarkly over the internet, so it has no VPC configuration.                                                                                                              |
| A policy on P0's role in the account                   | `lambda:InvokeFunction` on the connector's function, and nothing else.                                                                                                                                    |

### What the connector's Terraform creates on Google Cloud

| Resource                                                                            | What it's for                                                                                                                                                                                                                                          |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| The IAM and Cloud Run APIs, enabled in the connector's project                      | The service account and the Cloud Run service. Destroying the Terraform leaves them enabled, since other services may use them. If the first apply fails right after enabling them, apply again: a newly enabled API can take a few minutes to answer. |
| A service account, whose ID is the connector's name                                 | The identity the connector runs as. It has no role of its own. Each LaunchDarkly account's Terraform adds read access to that account's secret.                                                                                                        |
| The Cloud Run service, named after the connector                                    | Runs P0's connector image, `p0security/p0-connector-launchdarkly-gcloud`, pulled from Docker Hub by tag and digest. Its `INVOKER_SA_EMAIL` environment variable is P0's own service account, and the connector accepts calls from that account alone.  |
| `roles/run.invoker` and `roles/run.viewer` on the service, for P0's service account | Lets P0 call the connector, and read the service to find its address. Nothing on the project, and no one else.                                                                                                                                         |
| A check of the image's digest                                                       | Reads the tag's digest from Docker Hub on every plan, through a `docker` provider configured not to need a Docker daemon, and stops the plan if the tag no longer matches the pinned digest.                                                           |

{% hint style="warning" %}
**Don't destroy and recreate the connector's service account.** Google Cloud treats a recreated service account as a new identity, even with the same email, so it loses the read access that each LaunchDarkly account granted it. If you recreate it, apply each account's Terraform again, and deploy the connector again.
{% endhint %}

## Step 4: Add the LaunchDarkly account

{% hint style="warning" %}
**None of an account's settings can change once you add it, so check each one before you continue.** To use another connector, instance, secret manager or secret name, you remove the account and add it again. Read [#remove-an-account](#remove-an-account "mention") first.
{% endhint %}

1. On the LaunchDarkly integration's page in P0, select the **LaunchDarkly account** component, and add an account.
2. Enter an **Account name**, such as `acme-prod`. People name the account by it when they request access, as in `acme-prod/writer`, and access policies match it. It follows the same rule as a connector's ID.
3. Fill in the fields:

| Field                                               | What to enter                                                                                                                                                                        |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Connector**                                       | The connector that reaches this account. The list shows the connectors you've finished installing.                                                                                   |
| **LaunchDarkly instance**                           | Where your LaunchDarkly account is hosted: **Commercial** (`app.launchdarkly.com`), **EU** (`app.eu.launchdarkly.com`) or **Federal** (`app.launchdarkly.us`)                        |
| **Secret manager provider**                         | **AWS Secrets Manager** for a connector on AWS Lambda, or **Google Secret Manager** for one on Google Cloud Run                                                                      |
| **Installation**, under **Secret manager provider** | The account or project the secret is in. The list shows the ones where P0's integration for that secret manager is installed.                                                        |
| **Secrets region**, for AWS Secrets Manager         | The secret's region, such as `us-west-2`                                                                                                                                             |
| **Access token secret**                             | The name of the secret from [#step-2-store-the-access-token](#step-2-store-the-access-token "mention"). Enter the name, never an ARN or a resource name, and never the token itself. |

4. Continue to the account's setup page. It shows the token steps and the account's Terraform. Apply the Terraform after the connector's. It gives the connector read access to this account's secret, and to no other secret. On AWS, if a customer-managed KMS key encrypts the secret, set `kms_key_arn` in the Terraform to the key's ARN, not an alias, before you apply.

   For a secret on AWS in a different account from the connector, P0 gives you three pieces, in order:

   1. **Terraform for the connector's account:** read access on the connector's role. The plan fails until you set `kms_key_arn`.
   2. **Terraform for the secret's account:** the secret's resource policy, letting the connector's role read the secret. Apply it with credentials for the secret's account. **It replaces any resource policy the secret already has.** If the secret has one, add the statement to that policy instead of applying this. To check, run `aws secretsmanager get-resource-policy --secret-id <secret-name> --region <region>` in the secret's account.
   3. **A statement for the KMS key's policy,** as JSON. Add it to the policy of the key that encrypts the secret, beside the statements already there. Don't replace the key's policy with it.

   If the connector's role is ever deleted and created again, apply the second piece again and add the key statement again: AWS's policies name the old role, not the new one.
5. Continue in the installer. P0 checks the account through the connector, in this order:
   1. The connector can read the secret, and the secret holds a token.
   2. LaunchDarkly accepts the token, and says which LaunchDarkly account it belongs to.
   3. The connector's email domain pattern is set, and compiles.

P0 stops at the first check that fails. Its message starts `The LaunchDarkly account <account> failed its install check while`, names the check, such as `reading the access token's secret`, and says what to fix. If the fix is in LaunchDarkly, in the token, in the connector's read access or in the email domain pattern, make it and try again. If the fix is the connector, the instance, the secret manager or the secret's name, remove the account and add it again with the right value.

P0 adds each LaunchDarkly account only once. If the token belongs to a LaunchDarkly account that P0 already has under another name, P0 refuses the new one with a message that starts `The access token of the LaunchDarkly account <account> is for the same LaunchDarkly account as`.

When an admin checks the account again later, and the secret's token now belongs to another LaunchDarkly account, the check fails with `The access token for the LaunchDarkly account <account> now belongs to a different LaunchDarkly account than the one it was added for. Put that account's token back in the secret, or remove this account from P0 and add it again.`

Once the checks pass, the account's page shows what P0 read through the connector: the **LaunchDarkly account ID**, the **Token kind**, the **Token owner** and the **Allowed domains**. P0 also warns that the token stops working when its member leaves LaunchDarkly.

{% hint style="warning" %}
**Keep the connector's read access to the secrets of its own accounts, and to nothing else.** P0 names the secret in each call to the connector, so any other secret the connector can read, whether through a wildcard or through a grant on the whole account or project, is one a call could point it at.
{% endhint %}

The connector needs these permissions on each account's secret, which the account's Terraform grants:

| Secret manager        | What the connector's identity needs                                                                                                                                                                                       |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AWS Secrets Manager   | `secretsmanager:GetSecretValue` on the secret, and `kms:Decrypt` on its key if a customer-managed KMS key encrypts it                                                                                                     |
| Google Secret Manager | `roles/secretmanager.secretAccessor` and `roles/secretmanager.viewer`, both on the secret. The connector reads the secret's latest version and then that version's metadata, and the accessor role covers only the first. |

{% hint style="success" %}
People can now request access on the account. See [Requesting LaunchDarkly access](https://docs.p0.dev/integrations/resource-integrations/launchdarkly/requesting-access.md).
{% endhint %}

## Install with Terraform

{% hint style="info" %}
The `p0_launchdarkly_*` resources require P0 Terraform provider [v0.86.0](https://github.com/p0-security/terraform-provider-p0/releases/tag/v0.86.0) or later.
{% endhint %}

Instead of the installer, you can install LaunchDarkly with the P0 Terraform provider (see [Manage integrations as code with the P0 Terraform provider](https://docs.p0.dev/getting-started/get-started-with-the-p0-terraform-provider.md)). You still create and store the access token, as in [#step-1-create-the-access-token](#step-1-create-the-access-token "mention") and [#step-2-store-the-access-token](#step-2-store-the-access-token "mention"). Each resource's page in the Terraform registry has a complete example for each cloud, including the cloud resources. Create the resources in this order:

1. **Stage the connector** with [`p0_launchdarkly_connector_staged`](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/launchdarkly_connector_staged). Set `id` and `hosting`. For Google Cloud Run, P0 answers with `hosting.connector_service_account`, the service account the connector must run as.
2. **Deploy the connector** where `hosting` says, and set its `DOMAIN_ALLOW_PATTERN` environment variable. The pattern isn't an attribute of any P0 resource. Write it as described in [#the-email-domain-pattern](#the-email-domain-pattern "mention"), such as `"example[.]com"`. Pin the connector's image to a published tag and that tag's digest: copy both from the latest `p0_launchdarkly_connector` example in the Terraform registry. P0 publishes the tags on Docker Hub.
   * **AWS Lambda:** use the image `p0security/p0-connector-launchdarkly`, copied into Amazon ECR. Name the function's role after the connector, and give P0's AWS IAM management role `lambda:InvokeFunction` on the function.
   * **Google Cloud Run:** use the image `p0security/p0-connector-launchdarkly-gcloud`, running as `hosting.connector_service_account`. Give P0's Google Cloud service account `roles/run.invoker` and `roles/run.viewer` on the service, and set the connector's `INVOKER_SA_EMAIL` environment variable to that same service account's email. The connector refuses every call while `INVOKER_SA_EMAIL` is unset.
3. **Install the connector** with [`p0_launchdarkly_connector`](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/launchdarkly_connector), with the same `id` and `hosting` as the staged resource. P0 checks that it can invoke the connector.
4. **Give the connector read access to the secret**, with the permissions in [#step-4-add-the-launchdarkly-account](#step-4-add-the-launchdarkly-account "mention").
5. **Add each account** with [`p0_launchdarkly_account`](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/launchdarkly_account). Set `id`, `connector`, `instance` (`commercial`, `eu` or `federal`), `vault` and `token_secret_name`, the name of the access token's secret, and make it depend on the secret's read access.

For example, an account on a connector that runs on Google Cloud Run:

```terraform
resource "p0_launchdarkly_account" "acme_prod" {
  id        = "acme-prod"
  connector = p0_launchdarkly_connector.prod.id
  instance  = "commercial"

  vault = {
    type       = "gcp-sm"
    project_id = "my-secrets-project"
  }
  token_secret_name = "launchdarkly-acme-prod-token"

  depends_on = [
    google_secret_manager_secret_iam_member.launchdarkly_accessor,
    google_secret_manager_secret_iam_member.launchdarkly_viewer,
  ]
}
```

Creating the account has P0 check it through the connector, as in [#step-4-add-the-launchdarkly-account](#step-4-add-the-launchdarkly-account "mention"). If a check fails, the apply fails with P0's message. Fix what the message names and apply again. Once the checks pass, P0 fills in the account's `account_id`, `token_kind`, `token_owner_member_id` and `allowed_domains`.

Changing any of an account's attributes replaces the account, and changing a connector's `id` or `hosting` replaces the connector. Read [#remove-an-account](#remove-an-account "mention") before you apply a replacement.

### Import what you added in the P0 app

If you already added a connector or an account in the P0 app, the apply fails and says to import it. Import a connector into both of its resources, and an account into its one:

```bash
terraform import p0_launchdarkly_connector_staged.prod prod
terraform import p0_launchdarkly_connector.prod prod
terraform import p0_launchdarkly_account.acme_prod acme-prod
```

## Change the install later

### Rotate the access token

The connector reads the secret on every call, so it uses a new token from its next call. Nothing changes in P0 or in the Terraform. To rotate the token, or to replace a token whose admin left LaunchDarkly:

1. Create a new token for the same LaunchDarkly account, as in [#step-1-create-the-access-token](#step-1-create-the-access-token "mention").
2. Store it alone in the same secret as a new version. As in [#step-2-store-the-access-token](#step-2-store-the-access-token "mention"), run the command, paste the token and press Enter. For Google Secret Manager:

   ```bash
   read -rs LD_TOKEN
   printf %s "$LD_TOKEN" | gcloud secrets versions add <secret-name> \
     --project <project-id> \
     --data-file=-
   unset LD_TOKEN
   ```

   For AWS Secrets Manager:

   ```bash
   read -rs LD_TOKEN
   printf %s "$LD_TOKEN" | aws secretsmanager put-secret-value \
     --secret-id <secret-name> \
     --secret-string file:///dev/stdin \
     --region <region>
   unset LD_TOKEN
   ```
3. Click **Retry revoke** on each revoke that failed while the old token didn't work.
4. Reset or delete the old token in LaunchDarkly.

A token for another LaunchDarkly account doesn't work: P0 refuses requests and grants with it, and a revoke fails until the secret holds the account's own token.

### Update the connector

To move the connector to a new image, change the image's pin in your copy of the connector's Terraform and apply it again. On both clouds the pin is `image_tag` and `image_digest`, in the Terraform's `locals`. For P0's latest build, copy both from the latest `p0_launchdarkly_connector` example in the Terraform registry. Nothing changes in P0.

* **AWS Lambda:** Terraform copies the new image into your ECR repository and redeploys the function, so run it where Docker is running, as for the first apply. To find a tag's digest, run `docker buildx imagetools inspect p0security/p0-connector-launchdarkly:<tag>` and copy the `Digest` it prints.
* **Google Cloud Run:** Terraform redeploys the Cloud Run service with the new image, which Cloud Run pulls from Docker Hub. You don't need Docker. Pin the tag's own digest: the multi-platform index digest, not the digest of one platform's image, which Docker Hub also lists on the tag's page. The plan compares the pin with the tag's index digest, so a per-platform digest stops it. If you have Docker, `docker buildx imagetools inspect p0security/p0-connector-launchdarkly-gcloud:<tag>` prints the index digest as `Digest`.

If the plan stops with `The connector image's tag doesn't resolve to the digest pinned here`, the tag on Docker Hub and the digest you pinned are different images. Terraform changes nothing: edit the pin so the tag and its digest match, and apply again.

### Remove a connector

Remove each LaunchDarkly account that uses the connector first, as in [#remove-an-account](#remove-an-account "mention"), and destroy each account's Terraform, which removes its read grant. Then destroy the connector's Terraform, and delete the connector in P0.

With the Terraform provider, P0 refuses to destroy a `p0_launchdarkly_connector` while an account uses it. The P0 app doesn't stop you from deleting such a connector, and its accounts then can't grant or revoke access until you add a connector with the same ID again.

* **AWS Lambda:** each account's grant is a policy on the connector's role, and Terraform doesn't delete a role that still has one, so destroying the connector's Terraform first fails.
* **Google Cloud Run:** destroying the connector deletes its service account. A read grant left behind on a secret names an account that no longer exists: remove it with that LaunchDarkly account's Terraform, or from the secret's permissions.

### Remove an account

{% hint style="warning" %}
**Removing an account from P0 doesn't revoke the access P0 granted on it.** People keep the access P0 gave them in LaunchDarkly, and P0 can't revoke it while the account isn't installed.
{% endhint %}

Before you remove an account, or add it again with other settings, let its open requests end, or revoke them. Check for open requests on the **Activity** tab of [Access Management](https://docs.p0.dev/access-management/access-management.md). If you remove an account while requests are open, a LaunchDarkly admin takes that access back by hand.
