忽略 Terraform 中 Azure 防火墙规则的更改

Ignoring changes for Azure Firewall rules in Terraform

我正在设置 azure 防火墙规则,我希望在源地址上设置忽略更改。谁能用正确的语法帮助我。

使用 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,
    ]
  }
}

我也试过了rule.Rule1.source_addresses

在我的环境中测试得到以下错误。

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

解决方案:您应该使用规则[0]而不是规则[0]。

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