Distribuire un'area di lavoro di Azure Databricks usando Terraform

La configurazione di esempio seguente usa il provider Terraform per distribuire un'area azurerm di lavoro di Azure Databricks. Si presuppone che sia stato eseguito l'accesso ad Azure (az login) nel computer locale con un utente di Azure con Contributor diritti per la sottoscrizione.

Per altre informazioni sul azurerm plug-in Terraform per Databricks, vedere azurerm_databricks_workspace.

Configurazione semplice

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}/"
}

Configurazione del provider

In Gestire aree di lavoro di Databricks con Terraform usare le configurazioni speciali per Azure:

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