Terraform integration
You can manage Databricks Git folders in a fully automated environment using Terraform and the databricks_repo Terraform resource. In your Terraform configuration (.tf
) file, set databricks_repo
to the URL of the Git repository you will use for your Git folder(s):
resource "databricks_repo" "this" {
url = "https://github.com/user/demo.git"
}
To use a Databricks service principal with specific Git credentials, add the following configuration of providers and resources:
- Set the provider
databricks
to the URL of your Databricks workspace. You will define the access tokendatabricks_obo_token
in another step.
provider "databricks" {
# Configuration options
}
# Example 'databricks' provider configuration
provider "databricks" {
alias = "sp"
host = "https://....cloud.databricks.com"
token = databricks_obo_token.this.token_value
}
- Define the resources for the Databricks service principal and the authorization token. You can find the service principal name in the Databricks account console under User management > Service principals.
resource "databricks_service_principal" "sp" {
display_name = "<service_principal_name_here>"
}
- Set the authorization token for your Databricks service principal account using the application ID for it. You can find the service principal's application ID in the Databricks account console under User management > Service principals.
resource "databricks_obo_token" "this" {
application_id = databricks_service_principal.sp.application_id
comment = "PAT on behalf of ${databricks_service_principal.sp.display_name}"
lifetime_seconds = 3600
}
- Set the Git credentials the service principal will use to access your Databricks workspace.
resource "databricks_git_credential" "sp" {
provider = databricks.sp
depends_on = [databricks_obo_token.this]
git_username = "<the_git_user_account_used_by_the_servcie_principal>"
git_provider = "<your_git_provider_string here>"
personal_access_token = "<auth_token_string_for_git_user>"
}