Skip to content

Commit ce8367e

Browse files
Optional Resource Group creation in adb-lakehouse module (#153)
* Optional Resource Group creation in adb-lakehouse module The commit contains the implementation for the workspace resource group. However this change requires to no more use the local.rg_location variable, since the value is known after the apply, and rhis force the replacement of all of the resources * Fix resource group name value in the azure data factory resource
1 parent b07bada commit ce8367e

File tree

8 files changed

+22
-16
lines changed

8 files changed

+22
-16
lines changed

examples/adb-lakehouse/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module "adb-lakehouse" {
2020
location = var.location
2121
spoke_vnet_address_space = var.spoke_vnet_address_space
2222
spoke_resource_group_name = var.spoke_resource_group_name
23+
create_resource_group = var.create_resource_group
2324
managed_resource_group_name = var.managed_resource_group_name
2425
databricks_workspace_name = var.databricks_workspace_name
2526
data_factory_name = var.data_factory_name

examples/adb-lakehouse/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
provider "azurerm" {
22
features {}
3-
skip_provider_registration = true
3+
resource_provider_registrations = "none"
44
}
55

66
provider "databricks" {

examples/adb-lakehouse/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ variable "location" {
55

66
variable "spoke_resource_group_name" {
77
type = string
8-
description = "(Required) The name of the Resource Group to create"
8+
description = "(Required) The name of the Resource Group to create or to use"
9+
}
10+
11+
variable "create_resource_group" {
12+
type = bool
13+
description = "(Optional) Creates resource group if set to true (default)"
14+
default = true
915
}
1016

1117
variable "managed_resource_group_name" {

modules/adb-lakehouse/key_vault.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "azurerm_key_vault" "example" {
22
count = var.key_vault_name != "" ? 1 : 0
33
name = var.key_vault_name
4-
location = local.rg_location
4+
location = var.location
55
resource_group_name = local.rg_name
66
enabled_for_disk_encryption = true
77
tenant_id = data.azurerm_client_config.current.tenant_id

modules/adb-lakehouse/network.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
resource "azurerm_virtual_network" "this" {
22
name = "VNET-${var.project_name}-${var.environment_name}"
3-
location = local.rg_location
3+
location = var.location
44
resource_group_name = local.rg_name
55
address_space = [var.spoke_vnet_address_space]
66
tags = var.tags
77
}
88

99
resource "azurerm_network_security_group" "this" {
1010
name = "databricks-nsg-${var.project_name}-${var.environment_name}"
11-
location = local.rg_location
11+
location = var.location
1212
resource_group_name = local.rg_name
1313
tags = var.tags
1414
}
1515

1616

1717
resource "azurerm_route_table" "this" {
1818
name = "route-table-${var.project_name}-${var.environment_name}"
19-
location = local.rg_location
19+
location = var.location
2020
resource_group_name = local.rg_name
2121
tags = var.tags
2222
}

modules/adb-lakehouse/storage.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "azurerm_storage_account" "dls" {
22
count = length(var.storage_account_names)
33
name = "dls${var.storage_account_names[count.index]}${var.environment_name}"
44
location = var.location
5-
resource_group_name = var.spoke_resource_group_name
5+
resource_group_name = local.rg_name
66
account_tier = "Standard"
77
account_replication_type = "GRS"
88
tags = var.tags

modules/adb-lakehouse/vnet_injected_databricks_workspace.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ locals {
44
"Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action",
55
"Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action",
66
]
7+
8+
managed_resource_group_name = var.managed_resource_group_name == "" ? "${var.databricks_workspace_name}-managed-rg" : var.managed_resource_group_name
79
}
810

911
resource "azurerm_subnet" "private" {
1012
name = "private-subnet-${var.databricks_workspace_name}"
11-
resource_group_name = var.spoke_resource_group_name
13+
resource_group_name = local.rg_name
1214
virtual_network_name = azurerm_virtual_network.this.name
1315

1416
address_prefixes = var.private_subnet_address_prefixes
@@ -25,7 +27,7 @@ resource "azurerm_subnet" "private" {
2527

2628
resource "azurerm_subnet" "public" {
2729
name = "public-subnet-${var.databricks_workspace_name}"
28-
resource_group_name = var.spoke_resource_group_name
30+
resource_group_name = local.rg_name
2931
virtual_network_name = azurerm_virtual_network.this.name
3032

3133
address_prefixes = var.public_subnet_address_prefixes
@@ -60,14 +62,10 @@ resource "azurerm_subnet_route_table_association" "public" {
6062
route_table_id = azurerm_route_table.this.id
6163
}
6264

63-
locals {
64-
managed_resource_group_name = var.managed_resource_group_name == "" ? "${var.databricks_workspace_name}-managed-rg" : var.managed_resource_group_name
65-
}
66-
6765
resource "azurerm_databricks_workspace" "this" {
6866
name = var.databricks_workspace_name
69-
resource_group_name = var.spoke_resource_group_name
70-
managed_resource_group_name = local.managed_resource_group_name
67+
resource_group_name = local.rg_name
68+
managed_resource_group_name = var.managed_resource_group_name
7169
location = var.location
7270
sku = "premium"
7371

modules/adb-uc-metastore/azure.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ resource "azurerm_databricks_access_connector" "access_connector" {
1111
identity {
1212
type = "SystemAssigned"
1313
}
14+
tags = var.tags
1415
}
1516

1617
resource "azurerm_storage_account" "unity_catalog" {
@@ -25,7 +26,7 @@ resource "azurerm_storage_account" "unity_catalog" {
2526

2627
resource "azurerm_storage_container" "unity_catalog" {
2728
name = "${var.metastore_storage_name}-container"
28-
storage_account_name = azurerm_storage_account.unity_catalog.name
29+
storage_account_id = azurerm_storage_account.unity_catalog.id
2930
container_access_type = "private"
3031
}
3132

0 commit comments

Comments
 (0)