> 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/databricks/installation.md).

# Installing Databricks

Install the P0 Databricks integration from the P0 app or with the P0 Terraform provider: the connector, then each Databricks account, workspace, and catalog.

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

Install the connector first, then each Databricks account, workspace, and catalog that P0 should manage, either from the P0 app or with the P0 Terraform provider. The P0 app shows the Terraform to apply for each component. For what each one is, see [Databricks](https://docs.p0.dev/integrations/resource-integrations/databricks.md#how-it-works).

## Before you begin

To install the integration, you need:

* An AWS account for the connector, with P0's AWS **IAM management** installed for it. See [Setting up AWS IAM management](https://docs.p0.dev/integrations/resource-integrations/aws/installation-methods.md). The connector must run in a commercial AWS region, not in GovCloud, China, ISO, or European Sovereign Cloud regions.
* An AWS admin of that account, to deploy the connector.
* A Databricks account admin, or a service principal that is one, to add each account and workspace, and to turn admin requests on or off. See [#sign-in-the-databricks-provider](#sign-in-the-databricks-provider "mention"). The P0 app has you add all of the Terraform to the configuration that holds the connector, so whoever applies it also needs AWS access to the connector's account.
* The ID and URL of each workspace you add. To find them, see Databricks' [Workspace instance names, URLs, and IDs](https://docs.databricks.com/aws/en/workspace/workspace-details#workspace-instance-names-urls-and-ids).
* A Unity Catalog metastore assigned to each workspace you add. P0 can't add a workspace without one.
* To add a catalog, a Databricks account admin who is also the catalog's owner, holds `MANAGE` on it, or is a metastore admin. Account admins don't get `MANAGE` on catalogs by default.
* Terraform 1.4 or later, with version 6.36.0 or later of the `hashicorp/aws` provider version 1.115.0 or later of the `databricks/databricks` provider, and version 3.x of the `kreuzwerker/docker` provider. P0's RDS security perimeter and Postgres or MySQL connector modules pin the AWS provider to 5.x, so keep the connector's Terraform in a configuration without them.
* `docker` and the AWS CLI wherever you run the connector's Terraform, with the AWS CLI signed in to the connector's AWS account. See [#the-connector-image](#the-connector-image "mention").
* Databricks accounts and workspaces that are reachable over the public internet. Workspaces that accept only private connections, and workspaces or account consoles that limit access with an IP access list, aren't supported.

P0 grants access only to users who already exist in Databricks. For what each requestor needs, see [Requesting Databricks access](https://docs.p0.dev/integrations/resource-integrations/databricks/requesting-access.md#before-you-request).

### The connector image

The connector runs P0's image, [`p0security/p0-connector-databricks`](https://hub.docker.com/r/p0security/p0-connector-databricks) on Docker Hub, pinned to a `sha-<commit>` tag and the digest that tag resolves to. A tag on Docker Hub can be pushed again, so the plan fails if the tag no longer resolves to the pinned digest. Lambda runs images only from Amazon ECR, so the connector's Terraform creates an ECR repository named `p0-connector-databricks`, with scan on push and immutable tags turned on, and copies the image into it by its digest. Because a tag in the repository can't be overwritten, nobody who can push to it can replace the image the Lambda runs. The copy runs `docker` and the AWS CLI on the machine that runs Terraform, and Terraform repeats it whenever the image's tag or digest changes. The image's digest in ECR can differ from the one pinned for Docker Hub, because the copy pulls only the image for the Lambda's platform. The Lambda runs the image by its ECR digest. The Lambda writes its logs to a CloudWatch log group, `/aws/lambda/p0-connector-databricks`, that the Terraform creates with 30-day retention. The Terraform tags the repository, the log group, the connector's IAM role, and its Lambda with `ManagedBy = "Terraform"` and `ManagedFor = "P0"`.

If you run Terraform somewhere without docker, such as HCP Terraform's remote runs, the apply fails at the `terraform_data` resource that copies the image, or at the `aws_ecr_image` data source that reads it back. The error doesn't mention Databricks. Apply the connector's Terraform from a machine that has docker and the AWS CLI.

If that machine can't pull from Docker Hub, mirror the image to a registry it can pull from, keeping its tag and digest. Then point the connector's Terraform at your mirror by changing the image's name in its `locals` block.

### Outbound web identity federation

{% hint style="warning" %}
The connector's Terraform, on either install path, turns on outbound web identity federation, a setting for the whole AWS account. Destroying that resource turns it off for everything in the account.
{% endhint %}

Before you apply, check whether outbound web identity federation is already on in the account:

```bash
aws iam get-outbound-web-identity-federation-info
```

If it's on, the output shows `"JwtVendingEnabled": true`, and `IssuerIdentifier` holds the account's issuer URL. Import it rather than create it, using the `terraform import` command in the comments of the connector's Terraform. If the command fails with a `FeatureDisabled` error, or shows `"JwtVendingEnabled": false`, it's off, and the connector's Terraform turns it on.

To turn it on yourself instead, run `aws iam enable-outbound-web-identity-federation`, which prints the issuer URL as `IssuerIdentifier`, then import it as above.

Both commands need AWS CLI 2.32.0 or later. Older versions, such as 2.15, don't have them. Run `aws --version` to check yours.

To remove the connector and leave federation on, replace the resource with a `removed` block before you destroy the rest. Terraform then stops managing the setting without turning it off. The connector's Terraform has this block in its comments, with the resource's name filled in. `removed` blocks need Terraform 1.7 or later:

```hcl
removed {
  from = aws_iam_outbound_web_identity_federation.<resource-name>
  lifecycle {
    destroy = false
  }
}
```

### Sign in the Databricks provider

The Terraform for each account, workspace, and catalog uses an account-level `databricks` provider, whose `host` is your account console URL and which has your `account_id`. Unless you configure how it signs in, the provider uses whatever Databricks credentials it finds, such as a Databricks CLI login. Each person who plans or applies then needs their own Databricks account admin login. A plan reads the Databricks resources, so it needs the same sign-in as an apply.

Whoever the provider signs in as needs:

* The account admin role.
* To add a catalog, an assignment to the catalog's workspace, with the `USER` permission or higher. The provider grants `MANAGE` on the catalog through the workspace that the grant's `provider_config` block names, and account admins aren't assigned to workspaces by default.
* To add a catalog, `MANAGE` on it, ownership of it, or metastore admin.

To run Terraform without personal logins, have the provider sign in as a Databricks service principal, using an identity token from an identity provider you already run Terraform with, such as your CI system or a cloud service account. The service principal has no secret to store or rotate, and one federation policy decides which workloads can sign in as it:

1. **Create a service principal** in the Databricks account, and give it the `account_admin` role. Don't create an OAuth secret for it. Whoever held the secret could act as an account admin.
2. **Add a federation policy** to the service principal that trusts your identity provider's tokens. Set its issuer, the subject of the identity that runs Terraform, and its audience, which defaults to your Databricks account ID. See Databricks' [Configure a federation policy](https://docs.databricks.com/aws/en/dev-tools/auth/oauth-federation-policy).
3. **Give it access to each catalog you add.** Assign the service principal to the catalog's workspace with the `USER` permission, and have the catalog's owner or a metastore admin grant it `MANAGE`:

   ```sql
   GRANT MANAGE ON CATALOG <catalog> TO `<application-id>`;
   ```
4. **Configure the provider** to sign in only as the service principal. In the Terraform from the P0 app, the provider is in each account's Terraform, with an `alias`. Add `auth_type` and `client_id` to it:

   ```hcl
   provider "databricks" {
     host       = "https://accounts.cloud.databricks.com"
     account_id = "<databricks-account-id>"
     auth_type  = "env-oidc"
     client_id  = "<application-id>"
   }
   ```

   With `auth_type = "env-oidc"`, the provider never uses a Databricks CLI login, client secret, or token left in the environment.
5. **Set `DATABRICKS_OIDC_TOKEN`** before each plan or apply, to an identity token from your identity provider with the audience that the federation policy expects. For example, for a Google Cloud service account that the federation policy trusts:

   ```bash
   export DATABRICKS_OIDC_TOKEN=$(gcloud auth print-identity-token \
     --impersonate-service-account=<service-account-email> \
     --audiences=<databricks-account-id>)
   ```

   Google identity tokens last an hour, so mint a new one for a later plan. In GitHub Actions, set `auth_type = "github-oidc"` instead and give the workflow the `id-token: write` permission. The provider then requests the token from GitHub itself. See Databricks' [Enable workload identity federation for GitHub Actions](https://docs.databricks.com/aws/en/dev-tools/auth/provider-github).

## Install from the P0 app

Open [p0.app](https://p0.app), click **Integrations**, and under **Resources** select **Databricks**. P0 lists the components alphabetically, but install them in this order: **Connector**, **Account**, **Workspace**, then **Catalog**. When you've applied a component's Terraform, P0 checks that it can reach what the Terraform set up, and if it can't, the error says what to fix.

### Install the connector

1. Select the **Connector** component, then click **Add connector**.
2. In **Connector AWS account**, select the AWS account the connector runs in. The list shows the AWS accounts where P0's AWS IAM management is installed and that don't have a connector yet. If P0's AWS IAM management isn't installed for any account, P0 asks you to install it first.
3. In **Region**, select the AWS region for the connector.
4. In **Allowed email domains**, enter a regular expression that matches the email domains of the users P0 may grant access to, such as `example\.com`. Then click **Next**.
5. Add the providers that P0 lists to your Terraform configuration, then add the connector's Terraform. Apply it as an AWS admin of the account, then click **Next**. P0 checks that it can invoke the connector. If AWS refuses the call or can't find the Lambda yet, P0 tries again for about half a minute before it reports the failure.
6. Click **Finish**.

The connector checks the domain after the `@` in each requestor's P0 email and in their Databricks username, never in the other emails on their Databricks user. The match ignores case, and the pattern must match the whole domain: `example\.com` doesn't match `mail.example.com`. To allow subdomains, use `(.+\.)?example\.com`. To allow several domains, separate them with `|`, as in `example\.com|example\.org`. If your users' Databricks usernames are on another domain, such as Azure UPNs, include that domain too.

The connector's Terraform sets the pattern as the Lambda's `DOMAIN_PATTERN` environment variable. Keep your copy of that Terraform: P0 shows it only while you add the connector, and you change the pattern and the connector's image in it later. See [#change-the-install-later](#change-the-install-later "mention").

### Add a Databricks account

1. Select the **Account** component, then click **Add account**.
2. In **Account ID**, enter your Databricks account ID. To find it, see Databricks' [Locate your account ID](https://docs.databricks.com/aws/en/admin/account-settings/#locate-your-account-id).
3. In **Connector**, select the connector that reaches this account. If you haven't added the connector yet, P0 asks you to install it first.
4. In **Accounts URL**, enter the account console URL for the cloud your account runs on, then click **Next**:
   * AWS: `https://accounts.cloud.databricks.com`
   * AWS GovCloud: `https://accounts.cloud.databricks.us`
   * Azure: `https://accounts.azuredatabricks.net`
   * Google Cloud: `https://accounts.gcp.databricks.com`
5. Add the Terraform that P0 shows to the Terraform configuration that holds the connector, and apply it as a Databricks account admin with AWS access to the connector's account. It creates P0's service principal in the account and adds a federation policy that lets the connector sign in as that principal with its AWS identity tokens. Then click **Next**.
6. In **Service principal application ID**, enter the value that `terraform output -raw <output-name>` prints where you applied the Terraform. P0 shows the command with the output's name, which ends in `_application_id`.
7. To let your users request account admin in this account, turn on **Enable account-admin requests**. P0's service principal then needs account admin itself.
8. Click **Finish**. If you turned on account-admin requests, P0 shows the Terraform that gives its service principal account admin. Add it to the same configuration, apply it as a Databricks account admin with AWS access to the connector's account, then click **Next**. P0 checks that it can sign in to the account as the service principal, and, with account-admin requests on, that the service principal is an account admin.

### Add a workspace

1. Select the **Workspace** component, then click **Add workspace**.
2. In **Workspace ID**, enter the workspace's ID, such as `1234567890123456`. When you're signed in to the workspace, it's the number after `?o=` in your browser's address bar.
3. In **Account**, select the Databricks account the workspace belongs to. If you haven't added an account yet, P0 asks you to install one first.
4. In **Workspace URL**, enter `https://` and the workspace's host in lowercase, with nothing after the host, such as `https://dbc-1234abcd-5678.cloud.databricks.com`. Leave out the `/?o=` and ID that your browser shows after it. Then click **Next**. The host is on the workspace domain of the cloud your account runs on:

   * AWS: `cloud.databricks.com`
   * AWS GovCloud: `cloud.databricks.us`
   * Azure: `azuredatabricks.net`
   * Google Cloud: `gcp.databricks.com`

   If the URL is on another cloud's workspace domain than the account's, P0 refuses it with `Workspaces in the account at <accounts-url> are served from <domain>. Enter this workspace's URL on that domain.` You can't change the URL after this step. To use another URL, remove the workspace and add it again.
5. Add the Terraform that P0 shows to the Terraform configuration that holds the account, and apply it as a Databricks account admin with AWS access to the connector's account. It assigns P0's service principal to the workspace with the `USER` permission. Then click **Next**. P0 checks that it can reach the workspace at the URL you entered, and that the URL belongs to this workspace ID. If the URL belongs to another workspace, P0 says which one. See [#if-a-step-fails](#if-a-step-fails "mention").
6. In **Workspace name**, enter a name for the workspace in P0, such as `analytics-prod`. Requests show it, and approval rules can match it with the `workspace` filter's `name` key. See [Databricks](https://docs.p0.dev/integrations/resource-integrations/databricks.md#available-filters).
7. To let your users request workspace admin on this workspace, turn on **Enable workspace-admin requests**. P0's service principal then needs to be a workspace admin itself.
8. Click **Finish**. If you turned on workspace-admin requests, P0 shows the workspace's Terraform with the `ADMIN` permission in place of `USER`. In your Terraform configuration, replace the workspace's `databricks_mws_permission_assignment` block with it. Apply it as a Databricks account admin with AWS access to the connector's account, then click **Next**. P0 checks that its service principal is a workspace admin.

### Add a catalog

1. Select the **Catalog** component, then click **Add catalog**. If you haven't added a workspace yet, P0 asks you to install one first.
2. In **Catalog key**, enter the catalog's name in lowercase, then `@` and the ID of the workspace that P0 reaches the catalog through, such as `main@1234567890123456`. Under the key, P0 lists the workspaces you've added, with their IDs. Once the key names one of them, P0 lists the keys of the catalogs it can already see through that workspace, leaving out catalogs already added through any workspace in the account. A catalog that isn't listed works too: P0 sees a catalog only once its service principal has privileges on it. P0 can't add a catalog whose name contains `#`, `?`, `%`, or `\`. Contact <support@p0.dev> if you need P0 to manage one.
3. Click **Next**. P0 refuses a key whose workspace you haven't added to P0.
4. Add the Terraform that P0 shows to the Terraform configuration that holds the account. Apply it as a Databricks account admin who is also the catalog's owner, holds `MANAGE` on it, or is a metastore admin, with AWS access to the connector's account: every apply of that configuration also refreshes the account's and the connector's resources. It grants P0's service principal `MANAGE` on the catalog. Then click **Next**.
5. Click **Finish**.

Add more catalogs the same way. Each new catalog needs only its own Terraform.

You can add each catalog once per metastore. Catalog names are unique within a metastore, so P0 refuses to add a catalog through a second workspace on the same metastore. It refuses when you click **Next** after the catalog's key, before you apply any Terraform, even if the catalog you added first isn't finished installing. Requests for that catalog go through the one you added first. To add it through another workspace instead, remove the first one.

{% hint style="warning" %}
The catalog's Terraform grants `MANAGE` with `databricks_grant`, which changes only P0's own grant. Don't use `databricks_grants` on a catalog that P0 manages, or on any schema, table, volume, or function in it. Each apply of `databricks_grants` removes every grant on its object that isn't in your configuration, including P0's `MANAGE` on the catalog and the privileges P0 has granted your users.
{% endhint %}

### If a step fails

When P0 can't check a component, the installer's message starts with what failed, such as `P0 can't reach the Databricks connector in AWS account <aws-account-id> (<region>)`, then says why and what to do. For example, it can end with:

* `Databricks is busy or unavailable. Try again in a few minutes.`
* `AWS doesn't let P0 invoke the p0-connector-databricks Lambda. Check that the connector's Terraform, which lets P0's role invoke the Lambda, is applied, then try again.`
* `AWS has no p0-connector-databricks Lambda in the connector's account and region. Check that the connector's Terraform is applied in that region. If it was just applied, give the Lambda a few minutes to deploy, then try again.`

When P0 can't reach a workspace you're adding, the message starts with `P0's service principal can't reach Databricks workspace <workspace-id> at <workspace-url>`, and the reason that follows starts with one of these:

* `Databricks workspace URL <workspace-url> belongs to workspace <other-workspace-id>, not <workspace-id>.` You can't change the URL of a workspace you're adding, so remove the workspace and add it again with its own URL.
* `Databricks workspace <workspace-id> has no Unity Catalog metastore.` Assign the workspace a metastore, then try again.
* `Service principal <application-id> can't call Databricks workspace <workspace-id> at <workspace-url>.` Check the URL, and that the workspace's Terraform is applied.

When you turn on admin requests and P0 can't find the role, the message starts with `P0 can't confirm its service principal is an account admin in Databricks account <account-id>` or `P0 can't confirm its service principal is an admin of Databricks workspace <workspace-id>`. Apply the Terraform that P0 showed when you turned the setting on, as a Databricks account admin with AWS access to the connector's account, then try again.

For other failures, the message includes the explanation that Databricks or AWS gave. When P0 can't load the catalog suggestions, it also asks you to check that the account's and the workspace's Terraform are still applied.

## Install with the P0 Terraform provider

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

Use the P0 Terraform provider's Databricks resources alongside the `hashicorp/aws`, `databricks/databricks`, and `kreuzwerker/docker` providers, at the versions listed in [#before-you-begin](#before-you-begin "mention"). To set up the P0 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).

To install the connector, a Databricks account, its workspaces, and their catalogs in one configuration, start from [Installing Databricks in one configuration](https://registry.terraform.io/providers/p0-security/p0/latest/docs/guides/databricks) in the Terraform registry. Each resource in it refers to the one before it, so you don't copy IDs between them.

Each resource's page in the Terraform registry has a complete example, including the AWS and Databricks resources: [`p0_databricks_connector`](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/databricks_connector), [`p0_databricks_account`](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/databricks_account), [`p0_databricks_workspace`](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/databricks_workspace), and [`p0_databricks_catalog`](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/databricks_catalog). Start from those examples, and create the resources in this order:

1. **Stage the connector** with `p0_databricks_connector_staged`. Set `id` to the AWS account ID, and set `region` and `domain_pattern`. In HCL, escape each backslash in the pattern, as in `"example\\.com"`. Add `lifecycle { ignore_changes = [domain_pattern] }`, as the example does, so that changing the pattern later doesn't replace the connector.
2. **Deploy the connector** in that AWS account and region:

   * Turn on outbound web identity federation for the AWS account.
   * Create an IAM role named `p0-connector-databricks` that Lambda can assume. Allow it to call `sts:GetWebIdentityToken` only for the audience `databricks`, which the staged resource exposes as `federation_audience`, and to write logs only to the Lambda's own CloudWatch log group, `/aws/lambda/p0-connector-databricks`, which you create.
   * Check that the connector image's tag resolves to the digest in the example, and copy the image by that digest into an ECR repository with immutable tags in that account, and deploy it as a Lambda function named `p0-connector-databricks` that runs as that role, on the `x86_64` architecture, with a 30-second timeout. Set the Lambda's `DOMAIN_PATTERN` environment variable to `domain_pattern`.
   * Let P0's AWS IAM management role invoke the Lambda through a policy on that role (`aws_iam_role_policy`), rather than a resource policy on the Lambda.

   Then create `p0_databricks_connector` with the same values and `lifecycle` block as the staged resource. P0 checks that it can invoke the connector, and retries for about half a minute while a new IAM policy takes effect. If the first apply is denied access, apply again.
3. **Stage each account** with `p0_databricks_account_staged`. Set `id` to the Databricks account ID, `connector` to the connector's `id`, and `accounts_url` to the account console URL.
4. **Create the service principal.** As a Databricks account admin, create P0's service principal with a federation policy that trusts the connector's role. The policy's issuer is the outbound web identity federation issuer of the connector's AWS account, its subject is the role's ARN, and its audience is `databricks`. To let your users request account admin in the account, also give the service principal the `account_admin` role. Then create `p0_databricks_account` with the same values as the staged resource, plus the service principal's `application_id`, and `is_account_admin_enabled = true` if you gave it the role. The example sets both from one local, `enable_account_admin`.
5. **Add each workspace.** Assign the service principal to the workspace with the `USER` permission, or with `ADMIN` to let your users request workspace admin there. Then create `p0_databricks_workspace` with the workspace ID as `id`, the Databricks account ID as `account`, the workspace's URL as `workspace_url`, a name for the workspace in P0 as `workspace_name`, and `is_workspace_admin_enabled = true` if you assigned `ADMIN`. The example sets the permission and `is_workspace_admin_enabled` from one local, `enable_workspace_admin`. A configuration that holds the workspace's `databricks_mws_workspaces` can pass its `workspace_id`, `workspace_url`, and `workspace_name` straight through. The workspace ID is the number after `?o=` in your browser's address bar when you're signed in to the workspace. The workspace URL is `https://` and the workspace's host in lowercase, with nothing after the host. A new `workspace_url` replaces the workspace in P0.
6. **Add each catalog.** As a Databricks account admin who is also the catalog's owner, holds `MANAGE` on it, or is a metastore admin, grant the service principal `MANAGE` on the catalog with `databricks_grant`. If the same configuration holds the workspace, add its `p0_databricks_workspace` to the grant's `depends_on`, so that Terraform creates the grant, and the catalog that depends on it, only after the workspace and its service principal assignment. Then create `p0_databricks_catalog` with the workspace ID as `workspace_id` and the catalog's name, in lowercase, as `catalog_name`. P0 identifies the catalog as `<catalog_name>@<workspace_id>`.

## Change the install later

### Change the allowed email domains

You can't change **Allowed email domains** in P0 once you've added the connector. Change the pattern on the connector's Lambda instead:

* **From the P0 app:** change `DOMAIN_PATTERN` in your copy of the connector's Terraform, and apply it.
* **With the P0 Terraform provider:** change the domain pattern in the `locals` block of your copy of the connector example, and apply it. The example's P0 connector resources ignore later changes to `domain_pattern`, so the apply changes only the Lambda, and Terraform doesn't replace the connector.

Either way, the connector's page in P0 keeps showing the pattern you entered when you added it, but the connector checks only the pattern set on its Lambda. Don't remove the connector from P0 to change the pattern: while it's removed, P0 can't revoke the access it granted in the connector's Databricks accounts. For what a narrower pattern changes, see [Databricks](https://docs.p0.dev/integrations/resource-integrations/databricks.md#known-behavior).

### Update the connector

To move the connector to a new image, change the image's tag and digest to the ones in the latest [`p0_databricks_connector` example](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/databricks_connector) in the Terraform registry, and apply. Change both together: if the tag doesn't resolve to the digest, the plan fails. Both are in the `locals` block of your copy of the connector's Terraform, whether you copied it from the P0 app or from the example. Terraform then copies the new image into your ECR repository and redeploys the Lambda. Nothing changes in P0. If you mirror the image, copy the new one to your registry first, keeping its tag and digest.

### Turn admin requests on or off

{% hint style="warning" %}
P0 needs its admin role in an account or on a workspace to revoke the admin access it granted there. Remove that role only after P0 has turned the setting off. P0 refuses to turn a setting off while an approved admin request for that account or workspace hasn't ended.
{% endhint %}

**To turn a setting on from the P0 app:**

1. Select the **Account** or **Workspace** component, then the account or workspace.
2. Turn on **Enable account-admin requests** or **Enable workspace-admin requests**, then click **Update**.
3. Apply the Terraform that P0 shows as a Databricks account admin with AWS access to the connector's account, then click **Next**. For an account, the Terraform adds the service principal's account admin role. For a workspace, it changes the service principal's assignment to `ADMIN`. P0 checks that its service principal holds the role, and keeps the setting off if it doesn't.

**To turn a setting off from the P0 app:**

1. Select the **Account** or **Workspace** component, then the account or workspace.
2. Turn off **Enable account-admin requests** or **Enable workspace-admin requests**, then click **Update**.
3. Wait for P0 to show the Terraform for the change. While an approved admin request there hasn't ended, P0 lists the requests in its place, in a message that starts with `P0 still manages account admin in Databricks account <account-id>` or `P0 still manages workspace admin on Databricks workspace <workspace-name> (<workspace-id>)`. Let them end, or revoke them. P0 checks again every few seconds.
4. Click **Next** before you apply anything. P0 turns the setting off.
5. Apply the change that P0 showed, as a Databricks account admin with AWS access to the connector's account. For an account, remove the service principal's `databricks_service_principal_role` block. For a workspace, change the `permissions` of its `databricks_mws_permission_assignment` block from `["ADMIN"]` to `["USER"]`. The service principal stays assigned to the workspace, which Unity Catalog privileges need.

**With the P0 Terraform provider:** change `is_account_admin_enabled` together with the service principal's `account_admin` role, or `is_workspace_admin_enabled` together with the permission of its workspace assignment, and apply. In the examples, `enable_account_admin` and `enable_workspace_admin` set both. P0 updates the account or workspace in place. When a setting turns on, P0 checks the role, and if the check fails, the apply fails and the setting stays off.

Before you turn a setting off with the provider, let the approved admin requests there end, or revoke them. While any remain, P0 refuses the change and the apply fails with the same `P0 still manages` error. Terraform can change the role in that apply before P0 refuses, so if it did, apply your previous configuration again to restore the role.
