From 63be7379c1437f94c97525d17166e2db1acca49a Mon Sep 17 00:00:00 2001 From: brown9804 Date: Thu, 12 Feb 2026 17:40:12 -0600 Subject: [PATCH 1/5] databricks template --- 5_analytics-bigdata/README.md | 1 + 5_analytics-bigdata/databricks/README.md | 76 +++++++++++++++++ 5_analytics-bigdata/databricks/main.tf | 64 ++++++++++++++ 5_analytics-bigdata/databricks/outputs.tf | 21 +++++ 5_analytics-bigdata/databricks/provider.tf | 38 +++++++++ .../databricks/terraform.tfvars | 21 +++++ 5_analytics-bigdata/databricks/variables.tf | 84 +++++++++++++++++++ README.md | 1 + 8 files changed, 306 insertions(+) create mode 100644 5_analytics-bigdata/databricks/README.md create mode 100644 5_analytics-bigdata/databricks/main.tf create mode 100644 5_analytics-bigdata/databricks/outputs.tf create mode 100644 5_analytics-bigdata/databricks/provider.tf create mode 100644 5_analytics-bigdata/databricks/terraform.tfvars create mode 100644 5_analytics-bigdata/databricks/variables.tf diff --git a/5_analytics-bigdata/README.md b/5_analytics-bigdata/README.md index 7633efe..031fb01 100644 --- a/5_analytics-bigdata/README.md +++ b/5_analytics-bigdata/README.md @@ -15,6 +15,7 @@ Last updated: 2026-02-09 ## Templates available - [Azure Data Factory](./data-factory) +- [Azure Databricks (Workspace)](./databricks) - [Azure Synapse Analytics (Workspace)](./synapse-analytics) diff --git a/5_analytics-bigdata/databricks/README.md b/5_analytics-bigdata/databricks/README.md new file mode 100644 index 0000000..7c62e08 --- /dev/null +++ b/5_analytics-bigdata/databricks/README.md @@ -0,0 +1,76 @@ +# Terraform Template - Azure Databricks (Workspace) + +Costa Rica + +[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/) +[brown9804](https://github.com/brown9804) + +Last updated: 2026-02-12 + +------------------------------------------ + +> This template contains Terraform configurations to create an Azure Databricks workspace. + +> [!IMPORTANT] +> Azure Databricks creates a **managed resource group** for service-managed infrastructure. You will typically see **two resource groups**: your main RG plus the Databricks-managed RG. This is expected behavior. + +## File Descriptions + +- **main.tf**: Creates/updates the Resource Group (idempotent ARM PUT) and the Databricks workspace. +- **variables.tf**: Defines input variables used in the Terraform configuration. +- **provider.tf**: Configures the AzureRM + AzAPI + Random providers. +- **terraform.tfvars**: Example values for variables. +- **outputs.tf**: Outputs such as the workspace ID and URL. + +## Variables + +| Variable Name | Description | Type | Example Value | +| --- | --- | --- | --- | +| `resource_group_name` | Resource Group name to deploy into (created if missing). | string | `"rg-analytics-dev"` | +| `location` | Azure region for the deployment. | string | `"eastus"` | +| `databricks_workspace_name` | Base workspace name. If suffix enabled, final is `-`. | string | `"dbw-analytics-dev"` | +| `sku` | Workspace SKU (`standard`, `premium`, `trial`). | string | `"standard"` | +| `managed_resource_group_name` | Optional base managed RG name. If omitted, Databricks auto-generates it. | string | `null` | +| `append_random_suffix` | Append random suffix to reduce name collisions. | bool | `true` | +| `random_suffix_length` | Length of the suffix when enabled. | number | `6` | +| `tags` | Tags applied to resources. | map(string) | `{ "env": "dev" }` | + +## Usage + +1. Authenticate: + + ```sh + az login + az account show + # If needed: + az account set --subscription "" + ``` + +2. Initialize: + + ```sh + terraform init -upgrade + ``` + +3. Validate and plan: + + ```sh + terraform validate + terraform plan + ``` + +4. Apply: + + ```sh + terraform apply -auto-approve + ``` + +> [!NOTE] +> If you disable `append_random_suffix`, you may hit name collisions. + + +
+ Total views +

Refresh Date: 2026-02-12

+
+ diff --git a/5_analytics-bigdata/databricks/main.tf b/5_analytics-bigdata/databricks/main.tf new file mode 100644 index 0000000..ba4dcfb --- /dev/null +++ b/5_analytics-bigdata/databricks/main.tf @@ -0,0 +1,64 @@ +# main.tf +# Creates an Azure Databricks workspace. + +data "azurerm_client_config" "current" {} + +# Resource group creation is idempotent in ARM (PUT). This will create the RG if it doesn't exist, +# or update tags if it already exists. +resource "azapi_resource" "resource_group" { + type = "Microsoft.Resources/resourceGroups@2022-09-01" + name = var.resource_group_name + location = var.location + parent_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}" + + body = jsonencode({ + tags = var.tags + }) + + response_export_values = [ + "id", + "name" + ] +} + +resource "random_string" "suffix" { + length = var.random_suffix_length + upper = false + special = false + numeric = true + + keepers = { + resource_group_name = var.resource_group_name + location = var.location + workspace_base = var.databricks_workspace_name + sku = lower(var.sku) + managed_rg_base = coalesce(var.managed_resource_group_name, "rg-databricks-managed-${var.databricks_workspace_name}") + } +} + +locals { + suffix = var.append_random_suffix ? random_string.suffix.result : "" + + workspace_name = var.append_random_suffix ? "${var.databricks_workspace_name}-${local.suffix}" : var.databricks_workspace_name + + managed_rg_name = ( + var.managed_resource_group_name == null + ? null + : (var.append_random_suffix ? "${var.managed_resource_group_name}-${local.suffix}" : var.managed_resource_group_name) + ) +} + +resource "azurerm_databricks_workspace" "ws" { + name = local.workspace_name + resource_group_name = var.resource_group_name + location = var.location + sku = lower(var.sku) + + managed_resource_group_name = local.managed_rg_name + + tags = var.tags + + depends_on = [ + azapi_resource.resource_group + ] +} diff --git a/5_analytics-bigdata/databricks/outputs.tf b/5_analytics-bigdata/databricks/outputs.tf new file mode 100644 index 0000000..7c45492 --- /dev/null +++ b/5_analytics-bigdata/databricks/outputs.tf @@ -0,0 +1,21 @@ +# outputs.tf + +output "resource_group_id" { + description = "The ID of the resource group." + value = azapi_resource.resource_group.id +} + +output "databricks_workspace_id" { + description = "The resource ID of the Databricks workspace." + value = azurerm_databricks_workspace.ws.id +} + +output "databricks_workspace_name" { + description = "The name of the Databricks workspace." + value = azurerm_databricks_workspace.ws.name +} + +output "databricks_workspace_url" { + description = "The workspace URL of the Databricks workspace." + value = azurerm_databricks_workspace.ws.workspace_url +} diff --git a/5_analytics-bigdata/databricks/provider.tf b/5_analytics-bigdata/databricks/provider.tf new file mode 100644 index 0000000..b7b19a5 --- /dev/null +++ b/5_analytics-bigdata/databricks/provider.tf @@ -0,0 +1,38 @@ +# provider.tf +# Provider configuration for Azure Databricks workspace deployment. + +terraform { + required_version = ">= 1.8, < 2.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.116" + } + + azapi = { + source = "Azure/azapi" + version = "~> 1.13" + } + + random = { + source = "hashicorp/random" + version = "~> 3.6" + } + } +} + +provider "azurerm" { + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } + + # Uses the current Azure CLI context (az login + az account set) + skip_provider_registration = false +} + +provider "azapi" { + # Uses the current Azure CLI context (az login + az account set) +} diff --git a/5_analytics-bigdata/databricks/terraform.tfvars b/5_analytics-bigdata/databricks/terraform.tfvars new file mode 100644 index 0000000..240c0c5 --- /dev/null +++ b/5_analytics-bigdata/databricks/terraform.tfvars @@ -0,0 +1,21 @@ +resource_group_name = "rg-analytics-dev" +location = "eastus" + +# Databricks workspace names are unique within your subscription. +# This template appends a random suffix by default to reduce collisions. +databricks_workspace_name = "dbw-analytics-dev" + +# Optional. If omitted, Databricks auto-generates the managed resource group name. +# managed_resource_group_name = "rg-databricks-managed-analytics-dev" + +# SKU: standard | premium | trial +sku = "standard" + +append_random_suffix = true +random_suffix_length = 6 + +tags = { + env = "dev" + area = "analytics-bigdata" + iac = "terraform" +} diff --git a/5_analytics-bigdata/databricks/variables.tf b/5_analytics-bigdata/databricks/variables.tf new file mode 100644 index 0000000..d613537 --- /dev/null +++ b/5_analytics-bigdata/databricks/variables.tf @@ -0,0 +1,84 @@ +# variables.tf + +variable "resource_group_name" { + description = "The name of the Azure Resource Group to deploy into. This template will create the RG if it does not exist (idempotent ARM PUT)." + type = string + + validation { + condition = length(trimspace(var.resource_group_name)) > 0 + error_message = "resource_group_name must not be empty." + } +} + +variable "location" { + description = "The Azure region where the Resource Group and Databricks workspace will be created." + type = string + + validation { + condition = length(trimspace(var.location)) > 0 + error_message = "location must not be empty." + } +} + +variable "databricks_workspace_name" { + description = "Base name of the Azure Databricks workspace. If append_random_suffix is true, the final name will be '-'." + type = string + + validation { + condition = ( + length(trimspace(var.databricks_workspace_name)) > 0 + && can(regex("^[a-zA-Z0-9][a-zA-Z0-9-]*$", var.databricks_workspace_name)) + ) + error_message = "databricks_workspace_name must not be empty, start with alphanumeric, and contain only alphanumeric or '-'." + } +} + +variable "sku" { + description = "Databricks workspace SKU." + type = string + default = "standard" + + validation { + condition = contains(["standard", "premium", "trial"], lower(var.sku)) + error_message = "sku must be one of: standard, premium, trial." + } +} + +variable "managed_resource_group_name" { + description = "Optional base name of the Databricks managed resource group. If null/omitted, Databricks auto-generates it. If append_random_suffix is true, the final name will be '-'." + type = string + default = null + + validation { + condition = ( + var.managed_resource_group_name == null ? true : ( + length(try(trimspace(var.managed_resource_group_name), "")) > 0 + && length(try(var.managed_resource_group_name, "")) <= (var.append_random_suffix ? (90 - 1 - var.random_suffix_length) : 90) + ) + ) + error_message = "managed_resource_group_name must be 1-90 chars (or null to auto-generate) and leave room for '-' when append_random_suffix is true." + } +} + +variable "append_random_suffix" { + description = "Whether to append a random suffix to the workspace name (and managed RG name, if provided) to avoid collisions." + type = bool + default = true +} + +variable "random_suffix_length" { + description = "Length of the random suffix appended when append_random_suffix is true." + type = number + default = 6 + + validation { + condition = var.random_suffix_length >= 4 && var.random_suffix_length <= 16 + error_message = "random_suffix_length must be between 4 and 16." + } +} + +variable "tags" { + description = "A map of tags to assign to the resources." + type = map(string) + default = {} +} diff --git a/README.md b/README.md index c38bafa..a6d346f 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ Last updated: 2026-02-11 - [Analytics and Big Data](./5_analytics-bigdata) - [Azure Data Factory](./5_analytics-bigdata/data-factory) + - [Azure Databricks (Workspace)](./5_analytics-bigdata/databricks) - [Azure Synapse Analytics (Workspace)](./5_analytics-bigdata/synapse-analytics) From ab266040e9b58aa06d03c1564465eb2acb4c2ff5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 12 Feb 2026 23:42:15 +0000 Subject: [PATCH 2/5] Update last modified date in Markdown files --- 5_analytics-bigdata/README.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/5_analytics-bigdata/README.md b/5_analytics-bigdata/README.md index 031fb01..1a9cbad 100644 --- a/5_analytics-bigdata/README.md +++ b/5_analytics-bigdata/README.md @@ -5,7 +5,7 @@ Costa Rica [![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/) [brown9804](https://github.com/brown9804) -Last updated: 2026-02-09 +Last updated: 2026-02-12 ------------------------------------------ diff --git a/README.md b/README.md index a6d346f..17db11c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Costa Rica [![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/) [brown9804](https://github.com/brown9804) -Last updated: 2026-02-11 +Last updated: 2026-02-12 ---------- From d770e6cdb75e17cd3a8b324270b68e09e1cdeda0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 12 Feb 2026 23:42:17 +0000 Subject: [PATCH 3/5] Update visitor count --- 5_analytics-bigdata/databricks/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/5_analytics-bigdata/databricks/README.md b/5_analytics-bigdata/databricks/README.md index 7c62e08..5100343 100644 --- a/5_analytics-bigdata/databricks/README.md +++ b/5_analytics-bigdata/databricks/README.md @@ -70,7 +70,7 @@ Last updated: 2026-02-12
- Total views + Total views

Refresh Date: 2026-02-12

From 10ab1486f39c064564cbe339dd14f690f36a8ecb Mon Sep 17 00:00:00 2001 From: Timna Brown <24630902+brown9804@users.noreply.github.com> Date: Thu, 12 Feb 2026 17:44:49 -0600 Subject: [PATCH 4/5] Enhance README with images and formatting updates Added images and improved formatting in README.md. --- 5_analytics-bigdata/databricks/README.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/5_analytics-bigdata/databricks/README.md b/5_analytics-bigdata/databricks/README.md index 5100343..ca27c1e 100644 --- a/5_analytics-bigdata/databricks/README.md +++ b/5_analytics-bigdata/databricks/README.md @@ -12,7 +12,21 @@ Last updated: 2026-02-12 > This template contains Terraform configurations to create an Azure Databricks workspace. > [!IMPORTANT] -> Azure Databricks creates a **managed resource group** for service-managed infrastructure. You will typically see **two resource groups**: your main RG plus the Databricks-managed RG. This is expected behavior. +> - Azure Databricks creates a **managed resource group** for service-managed infrastructure. You will typically see **two resource groups**: your main RG plus the Databricks-managed RG. This is expected behavior. +> - If you disable `append_random_suffix`, you may hit name collisions. + +
+ image +
+ +
+ image +
+ +
+ image +
+ ## File Descriptions @@ -64,10 +78,7 @@ Last updated: 2026-02-12 ```sh terraform apply -auto-approve ``` - -> [!NOTE] -> If you disable `append_random_suffix`, you may hit name collisions. - +
Total views From e97bc9da97d3af6ca59cc30a3098a2052eb8a819 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 12 Feb 2026 23:45:04 +0000 Subject: [PATCH 5/5] Fix Markdown syntax issues --- 5_analytics-bigdata/databricks/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/5_analytics-bigdata/databricks/README.md b/5_analytics-bigdata/databricks/README.md index ca27c1e..9f8465a 100644 --- a/5_analytics-bigdata/databricks/README.md +++ b/5_analytics-bigdata/databricks/README.md @@ -12,6 +12,7 @@ Last updated: 2026-02-12 > This template contains Terraform configurations to create an Azure Databricks workspace. > [!IMPORTANT] +> > - Azure Databricks creates a **managed resource group** for service-managed infrastructure. You will typically see **two resource groups**: your main RG plus the Databricks-managed RG. This is expected behavior. > - If you disable `append_random_suffix`, you may hit name collisions. @@ -27,7 +28,6 @@ Last updated: 2026-02-12 image
- ## File Descriptions - **main.tf**: Creates/updates the Resource Group (idempotent ARM PUT) and the Databricks workspace.