IoT 中心的 IP 过滤器规则的 Terraform 顺序

Terraform order of ip filter rules for IoT Hub

我想用 Terraform 部署多个 Azure 云资源。我的问题是 Azure IoT 中心的 terraform 脚本,特别是 ip 限制规则。根据文档我可以做这样的事情

 resource "azurerm_iothub" "iothubname" {
  name                = "somename"
  resource_group_name = azurerm_resource_group.someresourcegroup
  location            = azurerm_resource_group.somelocation

  sku {
    name     = "B2"
    capacity = "2"
  }

  fallback_route {
    enabled = true
  }



ip_filter_rule {
    action = "Accept"
    ip_mask ="some_ip_range_1"
    name = "some_name_1"
}



 ip_filter_rule {
      action = "Accept"
        ip_mask ="some_ip_range_2"
        name = "some_name_2"   }



ip_filter_rule {
      action = "Accept"
        ip_mask ="some_ip_range_3"
        name = "some_name_3"
  }



 ip_filter_rule {
      action = "Reject"
        ip_mask ="0.0.0.0/0"
        name = "everything_else"
  }

}

一切正常,除了 ip 规则的顺序与上面不同,在我的情况下,我绝对希望最后一条规则是 azure 上优先级最低的规则。 Azure IoT 中心按顺序应用筛选规则。

如何强制执行 ip 过滤器的特定顺序?

你可以尝试使用动态块

https://www.terraform.io/docs/configuration/expressions/dynamic-blocks.html

文件main.tf

resource "azurerm_iothub" "iothubname" {
  name                = "somename"
  resource_group_name = azurerm_resource_group.someresourcegroup
  location            = azurerm_resource_group.somelocation

  sku {
    name     = "B2"
    capacity = "2"
  }

  fallback_route {
    enabled = true
  }

  dynamic "ip_filter_rule" {
  for_each = var.ip_filter_rule_list
    content {
      action = ip_filter_rule.value.action
      ip_mask = ip_filter_rule.value.ip_mask
      name = ip_filter_rule.value.name
    }
  }
}

文件variables.tf

variable "ip_filter_rule_list" {
type = list
default = []
}

更新

错误已在 terraform 提供程序 azurerm v2.57.0 中修复

https://github.com/terraform-providers/terraform-provider-azurerm/pull/11390