Skip to content

About

Azure Databricks Terraform module — parameterised, azurerm 4.x, CI-validated · AIRCLOUD

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

AIRCLOUD: DevOps, cloud and AI engineering

azure-databricks-module

Azure Databricks Terraform module — parameterised, azurerm 4.x, CI-validated.

CI License: MIT Release

This Terraform module creates an Azure Databricks workspace with enterprise-grade security features, VNet injection, cluster management, job orchestration, and SQL warehouses.

Features

  • Databricks Workspace: Premium SKU with managed resource group
  • VNet Injection: Secure deployment within customer VNet
  • Customer-Managed Keys: Encryption with Azure Key Vault
  • Private Endpoints: Secure access without public IP
  • Interactive Clusters: Configurable Spark clusters for development
  • Job Clusters: Dedicated clusters for ETL workloads
  • Job Orchestration: Multi-task jobs with dependencies
  • SQL Warehouses: Serverless SQL analytics
  • Cluster Policies: Governance and cost control
  • Azure Policy Integration: Compliance and security policies
  • Comprehensive Monitoring: Diagnostic settings and logging

Usage

Pin the module to a release tag:

module "databricks" {
  source = "git::https://github.com/AIRCLOUD-PL/azure-databricks-module.git?ref=v1.0.0"

  # required inputs
  environment         = "..."
  location            = "..."
  resource_group_name = "..."
}

All inputs and outputs are listed in the generated reference below (Inputs, Outputs). Worked examples live in examples/.

Basic Example

module "databricks" {
  source = "git::https://github.com/AIRCLOUD-PL/azure-databricks-module.git?ref=v1.0.0"

  resource_group_name = "rg-databricks"
  location           = "westeurope"
  environment        = "prod"

  sku = "premium"

  tags = {
    Environment = "prod"
    Project     = "data-platform"
  }
}

Complete Example with VNet Injection

module "databricks" {
  source = "git::https://github.com/AIRCLOUD-PL/azure-databricks-module.git?ref=v1.0.0"

  resource_group_name = "rg-databricks"
  location           = "westeurope"
  environment        = "prod"

  # VNet injection
  no_public_ip       = true
  virtual_network_id = azurerm_virtual_network.vnet.id
  private_subnet_name = "snet-databricks-private"
  public_subnet_name  = "snet-databricks-public"

  # Customer-managed key
  customer_managed_key = {
    key_vault_key_id = azurerm_key_vault_key.databricks.id
  }

  # Storage account for DBFS
  storage_account_name = azurerm_storage_account.dbfs.name

  # Security settings
  public_network_access_enabled = false

  # Interactive clusters
  interactive_clusters = {
    "data-eng-cluster" = {
      spark_version = "13.3.x-scala2.12"
      node_type_id  = "Standard_DS3_v2"
      num_workers   = 4
      autotermination_minutes = 120
      spark_conf = {
        "spark.databricks.delta.preview.enabled" = "true"
        "spark.sql.adaptive.enabled" = "true"
      }
      custom_tags = {
        "Team" = "Data Engineering"
        "CostCenter" = "DE-001"
      }
    }
  }

  # Job clusters
  job_clusters = {
    "etl-cluster" = {
      spark_version = "13.3.x-scala2.12"
      node_type_id  = "Standard_DS3_v2"
      num_workers   = 2
      autotermination_minutes = 60
    }
  }

  # ETL jobs
  jobs = {
    "daily-etl" = {
      job_cluster = {
        job_cluster_key = "etl-cluster"
        spark_version   = "13.3.x-scala2.12"
        node_type_id    = "Standard_DS3_v2"
        num_workers     = 2
      }
      tasks = [
        {
          task_key = "extract"
          notebook_task = {
            notebook_path = "/Shared/ETL/extract"
            base_parameters = {
              "source_path" = "/data/input"
            }
          }
        },
        {
          task_key = "transform"
          depends_on = [{ task_key = "extract" }]
          notebook_task = {
            notebook_path = "/Shared/ETL/transform"
          }
        },
        {
          task_key = "load"
          depends_on = [{ task_key = "transform" }]
          notebook_task = {
            notebook_path = "/Shared/ETL/load"
          }
        }
      ]
      schedule = {
        quartz_cron_expression = "0 0 6 * * ?"  # Daily at 6 AM
      }
      email_notifications = {
        on_failure = ["data-team@company.com"]
      }
      tags = {
        "team" = "data-engineering"
        "priority" = "high"
      }
    }
  }

  # SQL warehouses
  sql_warehouses = {
    "analytics-warehouse" = {
      cluster_size = "Medium"
      auto_stop_mins = 60
      tags = {
        "team" = "analytics"
      }
    }
  }

  # Private endpoints
  private_endpoints = {
    databricks = {
      subnet_id = azurerm_subnet.private.id
    }
  }

  tags = {
    Environment = "prod"
    Project     = "data-platform"
    Owner       = "Data Platform Team"
  }
}

Security Features

  • VNet Injection: Deploy Databricks within your virtual network
  • Private Endpoints: Secure access without public exposure
  • Customer-Managed Keys: Control encryption keys in Azure Key Vault
  • Infrastructure Encryption: Double encryption for sensitive data
  • Network Security: NSG associations and subnet delegations
  • Azure Policy: Compliance and governance policies

Monitoring and Logging

The module includes comprehensive diagnostic settings for:

  • Databricks workspace activity
  • Cluster operations
  • Job executions
  • SQL warehouse usage
  • Security events and audit logs

Testing

The module includes comprehensive Terratest coverage:

cd test
go test -v -run TestDatabricksModule

Tests cover:

  • Basic workspace creation
  • VNet injection configuration
  • Job orchestration
  • Private endpoint setup
  • Naming convention validation
  • SQL warehouse creation

Contributing

  1. Follow the established patterns for variable naming and resource configuration
  2. Include comprehensive test coverage for new features
  3. Update documentation for any new inputs or outputs
  4. Ensure compliance with enterprise security requirements

Reference

Requirements

Name Version
terraform >= 1.5.0
azurerm ~> 4.0
databricks ~> 1.0

Providers

Name Version
azurerm 4.81.0
databricks.workspace 1.145.0

Modules

No modules.

Resources

Name Type
azurerm_databricks_workspace.main resource
azurerm_private_endpoint.databricks resource
azurerm_resource_group_policy_assignment.databricks_diagnostic_settings resource
azurerm_resource_group_policy_assignment.databricks_encryption resource
azurerm_resource_group_policy_assignment.databricks_public_access resource
azurerm_resource_group_policy_assignment.databricks_vnet_injection resource
databricks_cluster.interactive_clusters resource
databricks_cluster.job_clusters resource
databricks_cluster_policy.policies resource
databricks_job.jobs resource
databricks_notebook.notebooks resource
databricks_permissions.cluster_permissions resource
databricks_permissions.job_permissions resource
databricks_sql_endpoint.warehouses resource
azurerm_resource_group.main data source

Inputs

Name Description Type Default Required
cluster_permissions Cluster permissions configuration
map(object({
access_control = list(object({
user_name = optional(string)
group_name = optional(string)
service_principal_name = optional(string)
permission_level = string
}))
}))
{} no
cluster_policies Cluster policies configuration
map(object({
definition = map(any)
}))
{} no
customer_managed_key Customer managed key configuration
object({
key_vault_key_id = string
})
null no
databricks_workspace_name Name of the Databricks workspace. If null, will be auto-generated. string null no
enable_policy_assignments Enable Azure Policy assignments for this Databricks workspace bool true no
environment Environment name (e.g., prod, dev, test) string n/a yes
infrastructure_encryption_enabled Enable infrastructure encryption bool true no
interactive_clusters Interactive clusters configuration
map(object({
spark_version = string
node_type_id = string
driver_node_type_id = optional(string)
num_workers = optional(number)

autoscale = optional(object({
min_workers = number
max_workers = number
}))

autotermination_minutes = optional(number, 60)
spark_conf = optional(map(string), {})
custom_tags = optional(map(string), {})
libraries = optional(list(object({
coordinates = string
})), [])

policy_id = optional(string)
}))
{} no
job_clusters Job clusters configuration
map(object({
spark_version = string
node_type_id = string
driver_node_type_id = optional(string)
num_workers = optional(number)

autoscale = optional(object({
min_workers = number
max_workers = number
}))

autotermination_minutes = optional(number, 60)
spark_conf = optional(map(string), {})
custom_tags = optional(map(string), {})
libraries = optional(list(object({
coordinates = string
})), [])

policy_id = optional(string)
}))
{} no
job_permissions Job permissions configuration
map(object({
access_control = list(object({
user_name = optional(string)
group_name = optional(string)
service_principal_name = optional(string)
permission_level = string
}))
}))
{} no
jobs Jobs configuration
map(object({
job_cluster = optional(object({
job_cluster_key = string
spark_version = string
node_type_id = string
driver_node_type_id = optional(string)
num_workers = optional(number)
autotermination_minutes = optional(number, 60)

autoscale = optional(object({
min_workers = number
max_workers = number
}))

spark_conf = optional(map(string), {})
custom_tags = optional(map(string), {})
}))

tasks = list(object({
task_key = string

notebook_task = optional(object({
notebook_path = string
base_parameters = optional(map(string), {})
}))

python_task = optional(object({
python_file = string
parameters = optional(list(string), [])
}))

spark_jar_task = optional(object({
main_class_name = string
parameters = optional(list(string), [])
}))

sql_task = optional(object({
query_id = string
warehouse_id = optional(string)
}))

depends_on = optional(list(string), [])
timeout_seconds = optional(number)
}))

parameters = optional(list(object({
name = string
value = string
})), [])

schedule = optional(object({
quartz_cron_expression = string
timezone_id = optional(string, "UTC")
}))

email_notifications = optional(object({
on_start = optional(list(string), [])
on_success = optional(list(string), [])
on_failure = optional(list(string), [])
}))

webhook_notifications = optional(object({
on_start = optional(list(object({
id = string
})), [])
on_success = optional(list(object({
id = string
})), [])
on_failure = optional(list(object({
id = string
})), [])
}))

timeout_seconds = optional(number)
max_concurrent_runs = optional(number, 1)
environments = optional(list(object({
environment_key = string
spec = object({
dependencies = optional(list(string), [])
})
})), [])

tags = optional(map(string), {})
}))
{} no
location Azure region where resources will be created string n/a yes
managed_resource_group_name Name of the managed resource group string null no
naming_prefix Prefix for Databricks naming string "databricks" no
no_public_ip Disable public IP for Databricks workspace bool true no
notebooks Notebooks configuration
map(object({
path = string
language = string
content = string
}))
{} no
private_endpoints Private endpoint configurations
object({
databricks = optional(object({
subnet_id = string
private_dns_zone_ids = optional(list(string))
}))
})
{} no
private_subnet_name Private subnet name for Databricks string null no
private_subnet_network_security_group_association_id Private subnet NSG association ID string null no
public_network_access_enabled Enable public network access bool false no
public_subnet_name Public subnet name for Databricks string null no
public_subnet_network_security_group_association_id Public subnet NSG association ID string null no
resource_group_name Name of the resource group string n/a yes
sku Databricks workspace SKU string "premium" no
sql_warehouses SQL warehouses configuration
map(object({
cluster_size = optional(string, "Small")
max_num_clusters = optional(number, 1)
min_num_clusters = optional(number, 1)
auto_stop_mins = optional(number, 120)
spot_instance_policy = optional(string, "COST_OPTIMIZED")
enable_serverless_compute = optional(bool, false)
tags = optional(map(string), {})
}))
{} no
storage_account_name Storage account name for Databricks string null no
storage_account_sku_name Storage account SKU name string "Standard_GRS" no
tags Tags to apply to all resources map(string) {} no
virtual_network_id Virtual network ID for VNet injection string null no

Outputs

Name Description
cluster_permissions Cluster permissions
databricks_managed_resource_group_id Managed resource group ID
databricks_managed_resource_group_name Managed resource group name
databricks_storage_account_name Storage account name for the Databricks workspace (deprecated in 4.x)
databricks_workspace_id Databricks workspace ID
databricks_workspace_name Databricks workspace name
databricks_workspace_url Databricks workspace URL
interactive_clusters Interactive clusters
job_clusters Job clusters
job_permissions Job permissions
jobs Jobs
notebooks Notebooks
private_endpoint_databricks_id Databricks private endpoint ID
sql_warehouses SQL warehouses

Part of the AIRCLOUD Azure module catalog

Browse all modules with usage snippets in the module catalog or on github.com/AIRCLOUD-PL. Built and maintained by AIRCLOUD: DevOps, cloud and AI engineering. Need a hand with Azure landing zones or platform engineering? See aircloud.com.pl/consulting.

About

Azure Databricks Terraform module — parameterised, azurerm 4.x, CI-validated · AIRCLOUD

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages