Terraform-合并顶级资源参数

时间:2020-09-18 10:53:38

标签: terraform

是否可以以某种方式定义map变量或类似的变量,然后将其扩展为顶级资源参数?类似于您在Yaml中进行<<:的操作。

我已经研究了合并地图和覆盖文件,但是看起来它们不适合此操作。

例如,我有这样的东西

resource "resource_type" "res1" {
  a = 1
  b = 2
  c = 3
  special = "res1"
}

resource "resource_type" "res2" {
  a = 1
  b = 2
  c = 3
  special = "res2"
}

我想要实现的目标:

locals {
  common_args = {
    a = 1
    b = 2
    c = 3
  }
}
  
resource "resource_type" "res1" {
  <put content of locals.common_args here>
  special = "res1"
}

resource "resource_type" "res2" {
  <put content of locals.common_args here>
  special = "res2"
}

1 个答案:

答案 0 :(得分:0)

如果可以使用count=for_each合并资源块,那可能是最好的。您仍然可以为每次迭代计算一个单独的“特殊”等。

但是,如果必须将它们分开,那么每个块中的这种资源属性模式都应该起作用:a = local.common_args["a"]