-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.tf
More file actions
64 lines (51 loc) · 1.78 KB
/
main.tf
File metadata and controls
64 lines (51 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
]
}