> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prequel.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Databricks

> Configuring your Databricks destination.

## Prerequisites

* By default, this Databricks integration makes use of Unity Catalog data governance features. You will need Unity Catalog enabled on your Databricks Workspace.

**1. Create a SQL warehouse**

Create a new SQL warehouse for data writing.

1. Log in to the Databricks account.
2. In the navigation pane, click **SQL Warehouses**.
3. In the SQL Warehouses console, click **Create SQL Warehouse**.
4. In the **New SQL Warehouse** menu, choose a **Name** and configure the options for the new SQL warehouse. Under "Advanced options" ensure "Unity Catalog" is in the **On** position and click **Create**.

![](https://storage.googleapis.com/prequel_docs/images/databricks-new-sql-warehouse-ui-refresh.png "databricks-new-sql-warehouse-ui-refresh.png")

5. Once the SQL warehouse is created, click the **Connection Details** tab, and make a note of the **Server hostname**, **Port**, and **HTTP path**.

![](https://storage.googleapis.com/prequel_docs/images/databricks-server-path-ui-refresh.png "databricks-server-path-ui-refresh.png")

**2. Configure Access**

> [tab] OAuth Secret (recommended)
>
> 1. In your Databricks workspace, click your username or icon in the top right, click **Settings**, **Identity and access**, and next to the **Service Principals** options, click **Manage**.
>
> 2. Click the **Add service principal** button, click **Add new** in the modal, enter a display name and click **Add**.
>
> 3. Click on the newly created Service Principal, and under the **Secrets** tab, click **Generate secret**.
>
> 4. Enter a lifetime for the secret (e.g., 90 days, 180 days, or 365 days), click **Generate** and make a note of the **Secret** value and **Client ID**. The **Client ID** is the **Application ID** of the Service Principal, not the ID of the secret.
>
> > [!NOTE]
> >
> > **Select the `all APIs` scope when generating the secret**
> >
> > The OAuth connection method currently requires the `all-apis` scope. If the Databricks UI prompts you to choose [scoped OAuth secrets](https://docs.databricks.com/aws/en/dev-tools/auth/oauth-m2m#-scoped-oauth-secrets) for the secret, select **all APIs**. Secrets limited to narrower scopes such as `sql` will fail to connect.
> >
> > This scope only controls which Databricks APIs the secret can call. What the service principal can read and write is still governed by the warehouse permission and Unity Catalog grants you configure in the following steps.
>
> 5. Navigate back to the **SQL Warehouses** section of your Workspace, click the **SQL Warehouses** tab, and select the **SQL Warehouse** you created in **Step 1**. Click **Permissions** in the top right, search for and select the **Service Principal** you created, select the **Can use** permission, and click **Add**.
> 6. In the Databricks UI, select the **Catalog** tab, and select the target **Catalog**. Within the catalog **Permissions** tab, click **Grant**. In the following modal, select the **Service principal** for which you generated the OAuth token, select `USE CATALOG`, and click **Grant**.
> 7. Under the target **Catalog**, select the target **schema** (e.g., `main.default`, or create a new target schema). Within the schema **Permissions** tab, click **Grant**. In the following modal, select the **principal** for which you generated the access token, and select either `ALL PRIVILEGES` or the following 9 privileges and then click **Grant**:
>    * `USE SCHEMA`
>    * `APPLY TAG`
>    * `MODIFY`
>    * `READ VOLUME`
>    * `SELECT`
>    * `WRITE VOLUME`
>    * `CREATE MATERIALIZED VIEW`
>    * `CREATE TABLE`
>    * `CREATE VOLUME`

> [tab] Personal Access Token (PAT)
>
> Create an access token for the data transfer service.
>
> 1. In the **SQL Warehouses** console, select the SQL warehouse you created in **Step 1**.
> 2. Click the **Connection Details** tab.
> 3. Click the link to Create a **personal access token**.
>
> ![](https://storage.googleapis.com/prequel_docs/images/databricks-create-personal-access-token-ui-refresh.png "create_a_personal_access_token.png")
>
> 4. Click **Generate New Token**.
> 5. Name the token with a descriptive comment and assign the token lifetime. A longer lifetime will ensure you do not have to update the token as often. If PAT scopes are enabled on your workspace, select the `sql` scope. Click **Generate**.
>
> ![](https://storage.googleapis.com/prequel_docs/images/databricks-pat-scopes.png "databricks-pat-scopes.png")
>
> 6. In the pop up that follows, **copy the token** and securely save the token.
>
> > [!WARNING]
> >
> > **Using a Service Principal & a Personal Access Token ("PAT") tied to the Service Account**
> >
> > You may prefer to create a **Service Principal** with a PAT to use for authentication instead of using your account's Personal Access Token. To do so, use the following steps to create a Service Principal and generate a PAT on behalf of the Service Principal.
> >
> > 1. In your Databricks workspace, click your username or icon in the top right, click **Settings**, **Identity and access**, and next to the **Service Principals** options, click **Manage**.
> > 2. Click the **Add service principal** button, click **Add new** in the modal, enter a display name and click **Add**.
> > 3. Click on the newly created Service Principal, and under **Entitlements** select **Databricks SQL Access** and **Workspace Access**. Click **Update**, and make a note of the **Application ID** of your newly created Service Principal.
> > 4. Back in the **Admin Settings** menu, click the **Advanced** section (under the **Workspace admin** menu). In the **Access Control** section, next to the **Personal Access Tokens** row, click **Permission Settings**. Search for and select the **Service Principal** you created, select the **Can use** permission, click **Add**, and then **Save**.
> > 5. Navigate back to the **SQL Warehouses** section of your Workspace, click the **SQL Warehouses** tab, and select the **SQL Warehouse** you created in **Step 1**. Click **Permissions** in the top right, search for and select the **Service Principal** you created, select the **Can use** permission, and click **Add**.
> > 6. Use your terminal to generate a **Service Principal Access Token** using your Personal Access Token generated above. Record the **token value**. This token can now be used as the access token for the connection.
> >
> > ```bash title="Generate access token" icon="terminal" expandable theme={null}
> > curl --request POST "https://<databricks-account-id>.cloud.databricks.com/api/2.0/token-management/on-behalf-of/tokens" \
> > --header "Authorization: Bearer <personal-access-token>" \
> > --data '{
> >   "application_id": "<application-id-of-service-principal>",
> >   "lifetime_seconds": <token-lifetime-in-seconds-eg-31536000>,
> >   "comment": "<some-description-of-this-token>"
> > }'
> > ```
>
> 7. In the Databricks UI, select the **Catalog** tab, and select the target **Catalog**. Within the catalog **Permissions** tab, click **Grant**. In the following modal, select the **principal** for which you generated the access token, select `USE CATALOG`, and click **Grant**.
> 8. Under the target **Catalog**, select the target **schema** (e.g., `main.default`, or create a new target schema). Within the schema **Permissions** tab, click **Grant**. In the following modal, select the **principal** for which you generated the access token, and select either `ALL PRIVILEGES` or the following 9 privileges and then click **Grant**:
>    * `USE SCHEMA`
>    * `APPLY TAG`
>    * `MODIFY`
>    * `READ VOLUME`
>    * `SELECT`
>    * `WRITE VOLUME`
>    * `CREATE MATERIALIZED VIEW`
>    * `CREATE TABLE`
>    * `CREATE VOLUME`

> [!NOTE]
>
> **System catalog access**
>
> In addition to the target catalog, the principal requires `USE CATALOG` on the Databricks `system` catalog. Databricks provides this access by default, so most organizations do not need to take any action. If your organization has restricted access to the `system` catalog, grant `USE CATALOG` on it to the principal.
>
> The `system` catalog is privilege aware. The principal can only see metadata for the objects it has already been granted access to. See Databricks documentation: [Information schema](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-information-schema).

> [!NOTE]
>
> **IP Access Lists (optional)**
>
> If your workspace enforces Databricks IP Access Lists, allowlist the static egress IP(s) used by the data transfer service so connections and test sessions can open successfully. See Databricks documentation: [Databricks IP Access Lists](https://learn.microsoft.com/en-us/azure/databricks/security/network/front-end/ip-access-list).
>
> Cloud Hosted (US): `35.192.85.117/32`
>
> Cloud Hosted (EU): `104.199.49.149/32`
>
> If private-cloud or self-hosted, contact support for the static egress IP.

**3. Add your destination**

Use the following details to complete the connection setup: **server hostname**, **HTTP path**, **catalog**, your chosen **schema name**, and authentication details.

## Terraform

If your organization manages infrastructure with Terraform, you can use the configuration below instead of the steps above. It sets up the same resources and permissions, using OAuth secret authentication.

* Use the official [`databricks/databricks`](https://registry.terraform.io/providers/databricks/databricks/latest/docs) provider. Run it as a workspace admin who can grant privileges on `catalog`.
* In `terraform.tfvars`, set `catalog` (an existing catalog), `schema_name`, and `warehouse_size`. The optional inputs and their defaults are `create_schema` (`true`), `warehouse_name` (`transfer-warehouse`), `serverless` (`true`), `service_principal_name` (`transfer-service-principal`), and `force_destroy_schema` (`false`).
* After `terraform apply`, use the `server_hostname`, `port`, `http_path`, `catalog`, `schema`, `client_id`, and `client_secret` outputs to complete the connection setup. Print each with `terraform output -raw <name>`.
* The client secret expires after 730 days. The next `terraform apply` after that creates a new secret, which you then update in the connection.

```hcl title="main.tf" icon="code" expandable theme={null}
terraform {
  required_providers {
    databricks = { source = "databricks/databricks" }
  }
}

variable "catalog" {
  type        = string
  description = "Existing Unity Catalog catalog to write into."
}

variable "schema_name" {
  type        = string
  description = "Target schema in the catalog (lowercase)."
}

variable "create_schema" {
  type        = bool
  default     = true
  description = "When enabled, creates the schema. When disabled, grants access to an existing schema named schema_name."
}

variable "warehouse_name" {
  type    = string
  default = "transfer-warehouse"
}

variable "warehouse_size" {
  type        = string
  description = "Size of the new SQL warehouse, e.g. 2X-Small."
}

variable "serverless" {
  type        = bool
  default     = true
  description = "When enabled, creates a serverless SQL warehouse. Disable it in workspaces without serverless compute to create a classic warehouse."
}

variable "service_principal_name" {
  type    = string
  default = "transfer-service-principal"
}

variable "force_destroy_schema" {
  type        = bool
  default     = false
  description = "When enabled, `terraform destroy` drops the schema even if it still contains tables."
}

resource "databricks_sql_endpoint" "transfer" {
  name                      = var.warehouse_name
  cluster_size              = var.warehouse_size
  auto_stop_mins            = 10
  enable_serverless_compute = var.serverless
  max_num_clusters          = 1
}

resource "databricks_service_principal" "transfer" {
  display_name          = var.service_principal_name
  databricks_sql_access = true
}

# Default scope is all-apis, which the connection requires. The secret expires
# after 730 days; the next apply after that creates a new one.
resource "databricks_service_principal_secret" "transfer" {
  service_principal_id = databricks_service_principal.transfer.id
}

# Grants Can use on the new warehouse. Terraform created this warehouse, so
# managing its whole permission set does not touch any warehouse you already have.
resource "databricks_permissions" "warehouse" {
  sql_endpoint_id = databricks_sql_endpoint.transfer.id
  access_control {
    service_principal_name = databricks_service_principal.transfer.application_id
    permission_level       = "CAN_USE"
  }
}

resource "databricks_grant" "catalog" {
  catalog    = var.catalog
  principal  = databricks_service_principal.transfer.application_id
  privileges = ["USE_CATALOG"]
}

resource "databricks_schema" "target" {
  count         = var.create_schema ? 1 : 0
  catalog_name  = var.catalog
  name          = var.schema_name
  force_destroy = var.force_destroy_schema
}

resource "databricks_grant" "schema" {
  schema    = "${var.catalog}.${var.schema_name}"
  principal = databricks_service_principal.transfer.application_id
  privileges = [
    "USE_SCHEMA",
    "APPLY_TAG",
    "MODIFY",
    "READ_VOLUME",
    "SELECT",
    "WRITE_VOLUME",
    "CREATE_MATERIALIZED_VIEW",
    "CREATE_TABLE",
    "CREATE_VOLUME",
  ]
  depends_on = [databricks_schema.target]
}

output "server_hostname" {
  value = databricks_sql_endpoint.transfer.odbc_params[0].hostname
}

output "port" {
  value = databricks_sql_endpoint.transfer.odbc_params[0].port
}

output "http_path" {
  value = databricks_sql_endpoint.transfer.odbc_params[0].path
}

output "catalog" {
  value = var.catalog
}

output "schema" {
  value = var.schema_name
}

output "client_id" {
  value = databricks_service_principal.transfer.application_id
}

output "client_secret" {
  value     = databricks_service_principal_secret.transfer.secret
  sensitive = true
}
```

```hcl title="terraform.tfvars" icon="code" expandable theme={null}
catalog        = "my_catalog"
schema_name    = "transfers"
warehouse_size = "2X-Small"
```

## Permissions checklist

* Workspace: Service principal or user has permission to use the target SQL warehouse ("Can use").
* Unity Catalog: `USE CATALOG` on the target catalog and on the `system` catalog (provided by default); appropriate privileges on the target schema (e.g., `USE SCHEMA`, `CREATE TABLE`, and read/write volume privileges as needed), or `ALL PRIVILEGES` on the schema.
* If using Hive Metastore (instead of UC): select `hive` metastore explicitly and configure required object storage staging (bucket and credentials), with write/delete permissions.
* Network: If IP Access Lists are enabled, the static egress IP(s) are allowlisted.

> [!NOTE]
>
> **Optional: Add a short retention lifecycle policy (Hive Metastore only)**
>
> If using an S3 staging bucket with Hive Metastore, you may configure a lifecycle rule on the bucket to automatically delete objects older than 2 days as the bucket is not used to persist data. In the bucket **Management** tab, click **Create lifecycle rule**, set an expiration action for current versions of objects with a 2-day age. Note that transfer logic automatically cleans up files after transfer completion, so this is an optional step.

## FAQ

> [accordion] What supported authentication method is recommended to securely connect to Databricks?
>
> Recommended: OAuth with a service principal. OAuth issues short-lived tokens, scopes access via the principal's entitlements and UC grants, and supports centralized rotation and revocation. Personal Access Tokens (PATs) are supported where policy requires, but they are long-lived bearer tokens and typically inherit broader, user-level permissions.

> [accordion] What permissions are required?
>
> The connection identity needs `Can use` on the SQL warehouse, `USE CATALOG` on the target catalog, and schema-level privileges to create/manage tables (or `ALL PRIVILEGES` on the schema). Missing `USE CATALOG` is a frequent cause of test-connection failures.

> [accordion] What credentials and connection details are required?
>
> Provide Server hostname, HTTP path, Catalog, Schema, and an OAuth client (service principal) or PAT with warehouse access. Collect host/path from the SQL Warehouses console.

> [accordion] Do you support Unity Catalog and Hive Metastore?
>
> Yes. Unity Catalog is the default. For Hive Metastore, explicitly select `hive` in configuration and supply an S3 staging bucket and credentials. Using the wrong metastore type can cause discovery or permission issues.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.