小编Mic*_*ele的帖子

Terraform 将元组展平为字符串集

我有以下 terraform allowed_ips 元组,其中包含 json 的 ip 地址和有关每个 ip 的元数据。我正在尝试展平元组,以获取格式为 ["2.2.2.2", "3.3.3.3"] 的 ip 地址列表,然后将其传递给 ip_rules 变量

多变的

allowed_ips = [
    {
      name       = "ip1"
      ip_address = "3.3.3.3"
    },
    {

      name       = "ip2"
      ip_address = "127.0.0.1"
    }
  ]


Run Code Online (Sandbox Code Playgroud)

资源

variable "allowed_ips" {
  type = list(object({
    name       = string,
    priority   = string,
    ip_address = string
  }))
}

network_acls {
    default_action = "Deny"
    bypass         = "AzureServices"

    ip_rules =  jsonencode(var.allowed_ips.*.ip_address)
  }
Run Code Online (Sandbox Code Playgroud)

当我设置规则时ip_rules = ["2.2.2.2", "3.3.3.3"],创建的规则没有问题,但我想以某种方式从上面的 allowed_ips 中解析变量。

我尝试过各种方法,包括

  • jsonencode(var.allowed_ips.*.ip_address)
  • "${join("\\,", local.subnets.*.id)}" …

string tuples azure terraform azure-rm

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

azure ×1

azure-rm ×1

string ×1

terraform ×1

tuples ×1