在 Terraform 中修改简单 list/array

Modify simple list/array in Terraform

我有下一个清单:

azs = ["us-east-1a", "us-east-1b", "us-east-1c"]

我在创建子网期间使用它。在子网的名称中,我想使用像 a, b, c 这样的短名称,所以我需要一个列表 ["a", "b", "c"]。显然,当 azs 将被手动设置时,我需要动态生成它(例如在 locals 块中)。

如何使用 Terraform 创建这样的列表?

您可以在这里使用 formatlist 函数来格式化列表。

它使用字符串格式语法,获取 n 个列表并返回单个列表。

所以在你的情况下你可能想要这样的东西:

locals {
  azs = [
    "a",
    "b",
    "c",
  ]
}

output "azs" {
  value = "${formatlist("us-east-1%s", local.azs)}"
}