'Ignoring changes for Azure Firewall rules in Terraform

I'm setting up an azure firewall rule and I wish to set ignore changes on the source addresses. Can anyone help me with the correct syntax.

Using hashicorp/azurerm v2.99.0.

resource "azurerm_firewall_nat_rule_collection" "FwRules" {
  name                          = "NATRules"
  azure_firewall_name           = var.afw_name
  resource_group_name           = var.rg_afw_name
  priority                      = 100
  action                        = "Dnat"

  rule {
    name                    = "Rule1"
    description             = "Allow Traffic"
    source_addresses        = []
    destination_ports       = ["3389"]
    destination_addresses   = [var.public_ip]
    translated_port         = "3389"
    translated_address      = azurerm_network_interface.vm1.private_ip_address
    protocols               = ["TCP"]
  }
  lifecycle {
    ignore_changes = [
      rules[0].source_addresses,
    ]
  }
}

I've also tried rule.Rule1.source_addresses



Solution 1:[1]

Tested in my environment getting the below error.

lifecycle {
    ignore_changes = [
      rules[0].source_addresses,
    ]
  }

enter image description here

Solution: You should use rule[0] not rules[0].

lifecycle {
    ignore_changes = [
      rule[0].source_addresses
      
    ]
  }

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RahulKumarShaw-MT