如何实现terraform嵌套循环结构?

时间:2018-05-09 16:38:01

标签: terraform

我正在尝试使用terraform管理我的github组织,并希望实现团队结构。

我已在地图中定义了团队结构,如下所示:

variable "teams" {
  description = "Map of teams with members"
  type        = "map"
  default     = {
    "TeamA"   = ["abc", "xyz", "pqr", "mno"]
    "TeamB"   = ["abc", "xyz", "mno"]
    "TeamC"   = ["pqr"]
  }
}

我可以使用以下资源代码创建这些团队:

resource "github_team" "sub-teams" {
  count           = "${length(keys(var.teams))}"
  name            = "${element(keys(var.teams), count.index)} Team"
  description     = "${element(keys(var.teams), count.index)} team"
  privacy         = "closed"
}

现在问题是循环地图的键,并将相应的团队成员添加到相应的团队。我该如何达到这个要求?

我提到this一个,但看起来它既有列表常量,也不符合上述情况。

1 个答案:

答案 0 :(得分:1)

terraform尚不支持嵌套地图。

您需要使用地图中的变量而不是使用数组。以下链接将带您进入git问题页面。

https://github.com/hashicorp/terraform/issues/2114