Skip to content

Commit a59eb4d

Browse files
authored
Fix incorrect use of location in adb-lakehouse module (#182)
When `create_resource_group` is set to `false` we trued to use the location of existing resource group, but it wasn't complete as some resources still used `location` passed as variable. With these changes we can omit `location` when we don't create a resource group, so we'll use default location from resource group itself. But if we don't create a resource group and `location` is set to non-empty value, then all resources will be created in that location. Also fixed specification of managed resource group for Databricks workspace. Resolves #181
1 parent cd5080f commit a59eb4d

9 files changed

+21
-14
lines changed

modules/adb-lakehouse/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ No modules.
8181
| <a name="input_databricks_workspace_name"></a> [databricks\_workspace\_name](#input\_databricks\_workspace\_name) | Name of Databricks workspace | `string` | n/a | yes |
8282
| <a name="input_environment_name"></a> [environment\_name](#input\_environment\_name) | (Required) The name of the project environment associated with the infrastructure to be managed by Terraform | `string` | n/a | yes |
8383
| <a name="input_key_vault_name"></a> [key\_vault\_name](#input\_key\_vault\_name) | The name of the Azure Key Vault to deploy. Won't be created if not specified | `string` | `""` | no |
84-
| <a name="input_location"></a> [location](#input\_location) | (Required) The location for the resources in this module | `string` | n/a | yes |
84+
| <a name="input_location"></a> [location](#input\_location) | (Optional if `create_resource_group` is set to `false`) The location for the resources in this module | `string` | n/a | yes |
8585
| <a name="input_managed_resource_group_name"></a> [managed\_resource\_group\_name](#input\_managed\_resource\_group\_name) | (Optional) The name of the resource group where Azure should place the managed Databricks resources | `string` | `""` | no |
8686
| <a name="input_private_subnet_address_prefixes"></a> [private\_subnet\_address\_prefixes](#input\_private\_subnet\_address\_prefixes) | Address space for private Databricks subnet | `list(string)` | n/a | yes |
8787
| <a name="input_project_name"></a> [project\_name](#input\_project\_name) | (Required) The name of the project associated with the infrastructure to be managed by Terraform | `string` | n/a | yes |
@@ -95,7 +95,8 @@ No modules.
9595

9696
| Name | Description |
9797
|-----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
98-
| <a name="output_azure_resource_group_id"></a> [azure\_resource\_group\_id](#output\_azure\_resource\_group\_id) | ID of the created Azure resource group |
98+
| <a name="output_azure_resource_group_id"></a> [azure\_resource\_group\_id](#output\_azure\_resource\_group\_id) | ID of the created or existing Azure resource group |
99+
| <a name="output_azure_resource_group_location"></a> [azure\_resource\_group\_location](#output\_azure\_resource\_group\_location) | Location of the created or existing Azure resource group |
99100
| <a name="output_nsg_id"></a> [nsg\_id](#output\_nsg\_id) | **Depricated** ID of the new NSG |
100101
| <a name="output_rg_id"></a> [rg\_id](#output\_rg\_id) | **Depricated** ID of the resource group |
101102
| <a name="output_rg_name"></a> [rg\_name](#output\_rg\_name) | **Depricated** Name of the resource group |
@@ -105,4 +106,4 @@ No modules.
105106
| <a name="output_workspace_name"></a> [workspace\_name](#output\_workspace\_name) | **Depricated** Name of the Databricks workspace |
106107
| <a name="output_workspace_resource_id"></a> [workspace\_resource\_id](#output\_workspace\_resource\_id) | **Depricated** ID of the Databricks workspace resource |
107108
| <a name="output_workspace_url"></a> [workspace\_url](#output\_workspace\_url) | URL of the Databricks workspace |
108-
<!-- END_TF_DOCS -->
109+
<!-- END_TF_DOCS -->

modules/adb-lakehouse/key_vault.tf

+1-1
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 = var.location
4+
location = local.rg_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/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data "azurerm_resource_group" "this" {
1313
locals {
1414
rg_name = var.create_resource_group ? azurerm_resource_group.this[0].name : data.azurerm_resource_group.this[0].name
1515
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
16+
rg_location = var.create_resource_group ? azurerm_resource_group.this[0].location : (var.location == "" ? data.azurerm_resource_group.this[0].location : var.location)
1717
}
1818

1919
data "azurerm_client_config" "current" {

modules/adb-lakehouse/network.tf

+3-3
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
3+
location = local.rg_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 = var.location
11+
location = local.rg_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 = var.location
19+
location = local.rg_location
2020
resource_group_name = local.rg_name
2121
tags = var.tags
2222
}

modules/adb-lakehouse/outputs.tf

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ output "workspace_url" {
4444
}
4545

4646
output "azure_resource_group_id" {
47-
description = "ID of the created Azure resource group"
47+
description = "ID of the created or existing Azure resource group"
48+
value = local.rg_id
49+
}
50+
51+
output "azure_resource_group_location" {
52+
description = "Location of the created or existing Azure resource group"
4853
value = local.rg_id
4954
}

modules/adb-lakehouse/providers.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
azurerm = {
4-
source = "hashicorp/azurerm"
4+
source = "hashicorp/azurerm"
55
version = ">=4.0.0"
66
}
77
}

modules/adb-lakehouse/storage.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
resource "azurerm_storage_account" "dls" {
22
count = length(var.storage_account_names)
33
name = "dls${var.storage_account_names[count.index]}${var.environment_name}"
4-
location = var.location
4+
location = local.rg_location
55
resource_group_name = local.rg_name
66
account_tier = "Standard"
77
account_replication_type = "GRS"

modules/adb-lakehouse/variables.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
variable "location" {
22
type = string
3-
description = "(Required) The location for the resources in this module"
3+
description = "(Optional if `create_resource_group` is set to `false`) The location for the resources in this module"
4+
default = ""
45
}
56

67
variable "spoke_resource_group_name" {

modules/adb-lakehouse/vnet_injected_databricks_workspace.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ resource "azurerm_subnet_route_table_association" "public" {
6565
resource "azurerm_databricks_workspace" "this" {
6666
name = var.databricks_workspace_name
6767
resource_group_name = local.rg_name
68-
managed_resource_group_name = var.managed_resource_group_name
69-
location = var.location
68+
managed_resource_group_name = local.managed_resource_group_name
69+
location = local.rg_location
7070
sku = "premium"
7171

7272
custom_parameters {

0 commit comments

Comments
 (0)