Skip to content

Commit fb433a0

Browse files
authored
Make creation of resource group for Databricks workspace optional (#115)
Very often you need to deploy ADB workspace into existing resource group, but current `adb-lakehouse` module always creates a new resource group. This PR allows to specify existing resource group name, while keeping compatibility with the previous version by creating it by default (could be disabled with the new variable).
1 parent fd873a8 commit fb433a0

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

modules/adb-lakehouse/azure_data_factory.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "azurerm_data_factory" "adf" {
22
count = var.data_factory_name != "" ? 1 : 0
33

44
name = var.data_factory_name
5-
location = var.location
6-
resource_group_name = azurerm_resource_group.this.name
5+
location = local.rg_location
6+
resource_group_name = local.rg_name
77
tags = var.tags
88
}

modules/adb-lakehouse/key_vault.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
resource "azurerm_key_vault" "example" {
22
count = var.key_vault_name != "" ? 1 : 0
33
name = var.key_vault_name
4-
location = var.location
5-
resource_group_name = azurerm_resource_group.this.name
4+
location = local.rg_location
5+
resource_group_name = local.rg_name
66
enabled_for_disk_encryption = true
77
tenant_id = data.azurerm_client_config.current.tenant_id
88
soft_delete_retention_days = 7
99
purge_protection_enabled = false
1010
sku_name = "standard"
1111
tags = var.tags
12-
}
12+
}

modules/adb-lakehouse/main.tf

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
resource "azurerm_resource_group" "this" {
2+
count = var.create_resource_group ? 1 : 0
23
name = var.spoke_resource_group_name
34
location = var.location
45
tags = var.tags
56
}
67

8+
data "azurerm_resource_group" "this" {
9+
count = var.create_resource_group ? 0 : 1
10+
name = var.spoke_resource_group_name
11+
}
12+
13+
locals {
14+
rg_name = var.create_resource_group ? azurerm_resource_group.this[0].name : data.azurerm_resource_group.this[0].name
15+
rg_id = var.create_resource_group ? azurerm_resource_group.this[0].id : data.azurerm_resource_group.this[0].id
16+
rg_location = var.create_resource_group ? azurerm_resource_group.this[0].location : data.azurerm_resource_group.this[0].location
17+
}
18+
719
data "azurerm_client_config" "current" {
8-
}
20+
}

modules/adb-lakehouse/network.tf

+6-6
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 = var.location
4-
resource_group_name = azurerm_resource_group.this.name
3+
location = local.rg_location
4+
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 = azurerm_resource_group.this.location
12-
resource_group_name = azurerm_resource_group.this.name
11+
location = local.rg_location
12+
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 = azurerm_resource_group.this.location
20-
resource_group_name = azurerm_resource_group.this.name
19+
location = local.rg_location
20+
resource_group_name = local.rg_name
2121
tags = var.tags
2222
}

modules/adb-lakehouse/outputs.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
output "rg_name" {
2-
value = azurerm_resource_group.this.name
3-
description = "Name of the new resource group"
2+
value = local.rg_name
3+
description = "Name of the resource group"
44
}
55

66
output "rg_id" {
7-
value = azurerm_resource_group.this.id
8-
description = "ID of the new resource group"
7+
value = local.rg_id
8+
description = "ID of the resource group"
99
}
1010

1111
output "vnet_id" {

modules/adb-lakehouse/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ variable "spoke_resource_group_name" {
88
description = "(Required) The name of the Resource Group to create"
99
}
1010

11+
variable "create_resource_group" {
12+
type = bool
13+
description = "(Optional) Creates resource group if set to true (default)"
14+
default = true
15+
}
16+
1117
variable "managed_resource_group_name" {
1218
type = string
1319
description = "(Optional) The name of the resource group where Azure should place the managed Databricks resources"

0 commit comments

Comments
 (0)