From c389f4c117c7c301fa2021ef443a467e1a6e56c7 Mon Sep 17 00:00:00 2001 From: Rupal Sharma <152851038+Rupalgw@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:24:37 +0530 Subject: [PATCH] fix:change in count condition (#29) --- main.tf | 4 ++-- outputs.tf | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index 670b1fb..9531f94 100644 --- a/main.tf +++ b/main.tf @@ -35,7 +35,7 @@ resource "azurerm_network_security_group" "nsg" { ## Below resource will create network security group inbound rules in azure and will be attached to above network security group. ##----------------------------------------------------------------------------- resource "azurerm_network_security_rule" "inbound" { - for_each = { for rule in var.inbound_rules : rule.name => rule } + for_each = var.enabled ? { for rule in var.inbound_rules : rule.name => rule } : {} resource_group_name = var.resource_group_name network_security_group_name = azurerm_network_security_group.nsg[0].name direction = "Inbound" @@ -65,7 +65,7 @@ resource "azurerm_network_security_rule" "inbound" { ## Below resource will create network security group outbound rules in azure and will be attached to above network security group. ##----------------------------------------------------------------------------- resource "azurerm_network_security_rule" "outbound" { - for_each = { for rule in var.outbound_rules : rule.name => rule } + for_each = var.enabled ? { for rule in var.outbound_rules : rule.name => rule } : {} resource_group_name = var.resource_group_name network_security_group_name = azurerm_network_security_group.nsg[0].name direction = "Outbound" diff --git a/outputs.tf b/outputs.tf index 034a83d..30dfd70 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,10 +1,10 @@ output "id" { - value = azurerm_network_security_group.nsg[0].id + value = try(azurerm_network_security_group.nsg[0].id, null) description = "The network security group configuration ID." } output "name" { - value = azurerm_network_security_group.nsg[0].name + value = try(azurerm_network_security_group.nsg[0].name, null) description = "The name of the network security group." } @@ -14,7 +14,7 @@ output "tags" { } output "subnet_id" { - value = azurerm_subnet_network_security_group_association.example[0].subnet_id + value = try(azurerm_subnet_network_security_group_association.example[*].subnet_id, null) description = "The ID of the Subnet. Changing this forces a new resource to be created." }