使用 Terraform 部署 Azure Databricks 工作区

以下示例配置使用 azurerm Terraform 提供程序部署 Azure Databricks 工作区。 它假定你已使用对你的订阅拥有 Contributor 权限的 Azure 用户登录到本地计算机上的 Azure (az login)。

有关 Databricks 的 azurerm Terraform 插件的详细信息,请参阅 azurerm_databricks_workspace

安装简单

terraform {
  required_providers {
    azurerm =  "~> 2.33"
    random = "~> 2.2"
  }
}

provider "azurerm" {
  features {}
}

variable "region" {
  type = string
  default = "westeurope"
}

resource "random_string" "naming" {
  special = false
  upper   = false
  length  = 6
}

data "azurerm_client_config" "current" {
}

data "external" "me" {
  program = ["az", "account", "show", "--query", "user"]
}

locals {
  prefix = "databricksdemo${random_string.naming.result}"
  tags = {
    Environment = "Demo"
    Owner       = lookup(data.external.me.result, "name")
  }
}

resource "azurerm_resource_group" "this" {
  name     = "${local.prefix}-rg"
  location = var.region
  tags     = local.tags
}

resource "azurerm_databricks_workspace" "this" {
  name                        = "${local.prefix}-workspace"
  resource_group_name         = azurerm_resource_group.this.name
  location                    = azurerm_resource_group.this.location
  sku                         = "premium"
  managed_resource_group_name = "${local.prefix}-workspace-rg"
  tags                        = local.tags
}

output "databricks_host" {
  value = "https://${azurerm_databricks_workspace.this.workspace_url}/"
}

提供程序配置

使用 Terraform 管理 Databricks 工作区中,使用 Azure 的特殊配置

provider "databricks" {
  host = azurerm_databricks_workspace.this.workspace_url
}