首页 > 解决方案 > 在嵌套块中使用计数

问题描述

Terraform 中有没有办法在嵌套块中使用计数参数?我不想创建资源的多个实例,我想使用资源生成动态数量的嵌套块。举个例子:

variable "envNames" {
  type = "list"
}

variable "envValues" {
  type = "list"
}


resource "test_resource" "example" {

  # If length(var.envNames) == 5, I would want 5 env blocks
  env {
    count = "${length(var.envNames)}"

    name  = "${element(var.envNames, count.index)}"
    value = "${element(var.envValues, count.index)}"
  }

}

看起来在 terraform v0.12 中我可以dynamic在块上使用关键字以及foreach声明和地图变量,但是在 v0.11 中有没有办法做到这一点?

如果有帮助,这适用于 Kubernetes 部署资源。

标签: terraform

解决方案


推荐阅读