Share via


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 Azure Databricks service principal with specific Git credentials, add the following configuration of providers and resources:

  1. Set the provider databricks to the URL of your Azure Databricks workspace. You will define the access token databricks_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
  }
  1. Define the resources for the Azure Databricks service principal and the authorization token. You can find the service principal name in the Azure Databricks account console under User management > Service principals.
  resource "databricks_service_principal" "sp" {
    display_name = "<service_principal_name_here>"
  }
  1. Set the authorization token for your Azure Databricks service principal account using the application ID for it. You can find the service principal's application ID in the Azure 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
  }
  1. Set the Git credentials the service principal will use to access your Azure 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>"
  }

Read more