File tree 6 files changed +34
-16
lines changed
6 files changed +34
-16
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ resource "azurerm_data_factory" "adf" {
2
2
count = var. data_factory_name != " " ? 1 : 0
3
3
4
4
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
7
7
tags = var. tags
8
8
}
Original file line number Diff line number Diff line change 1
1
resource "azurerm_key_vault" "example" {
2
2
count = var. key_vault_name != " " ? 1 : 0
3
3
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
6
6
enabled_for_disk_encryption = true
7
7
tenant_id = data. azurerm_client_config . current . tenant_id
8
8
soft_delete_retention_days = 7
9
9
purge_protection_enabled = false
10
10
sku_name = " standard"
11
11
tags = var. tags
12
- }
12
+ }
Original file line number Diff line number Diff line change 1
1
resource "azurerm_resource_group" "this" {
2
+ count = var. create_resource_group ? 1 : 0
2
3
name = var. spoke_resource_group_name
3
4
location = var. location
4
5
tags = var. tags
5
6
}
6
7
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
+
7
19
data "azurerm_client_config" "current" {
8
- }
20
+ }
Original file line number Diff line number Diff line change 1
1
resource "azurerm_virtual_network" "this" {
2
2
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
5
5
address_space = [var . spoke_vnet_address_space ]
6
6
tags = var. tags
7
7
}
8
8
9
9
resource "azurerm_network_security_group" "this" {
10
10
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
13
13
tags = var. tags
14
14
}
15
15
16
16
17
17
resource "azurerm_route_table" "this" {
18
18
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
21
21
tags = var. tags
22
22
}
Original file line number Diff line number Diff line change 1
1
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"
4
4
}
5
5
6
6
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"
9
9
}
10
10
11
11
output "vnet_id" {
Original file line number Diff line number Diff line change @@ -8,6 +8,12 @@ variable "spoke_resource_group_name" {
8
8
description = " (Required) The name of the Resource Group to create"
9
9
}
10
10
11
+ variable "create_resource_group" {
12
+ type = bool
13
+ description = " (Optional) Creates resource group if set to true (default)"
14
+ default = true
15
+ }
16
+
11
17
variable "managed_resource_group_name" {
12
18
type = string
13
19
description = " (Optional) The name of the resource group where Azure should place the managed Databricks resources"
You can’t perform that action at this time.
0 commit comments