Skip to content

Commit f0e2ae8

Browse files
authored
Merge pull request #8 from data-platform-hq/fix_switch_nsg_association_to_count_condition
fix: switched nsg association to count condition
2 parents 8ffcf05 + d71974b commit f0e2ae8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ resource "azurerm_subnet" "this" {
2121
}
2222

2323
resource "azurerm_subnet_network_security_group_association" "this" {
24-
for_each = var.nsg_id
24+
count = var.nsg_association_enabled ? 1 : 0
2525

2626
subnet_id = var.export_subnet_id == null ? azurerm_subnet.this[0].id : var.export_subnet_id
27-
network_security_group_id = each.value
27+
network_security_group_id = var.nsg_id
2828
}

variables.tf

+8-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ variable "delegations" {
4444
default = []
4545
}
4646

47+
variable "nsg_association_enabled" {
48+
type = bool
49+
description = "Boolean flag that determines if NSG association would be created"
50+
default = false
51+
}
52+
4753
variable "nsg_id" {
48-
type = map(string)
54+
type = string
4955
description = "The ID of the Network Security Group which should be associated with the Subnet"
50-
default = {}
56+
default = null
5157
}
5258

5359
variable "export_subnet_id" {

0 commit comments

Comments
 (0)