获取Terraform中的列表总数

时间:2018-03-20 21:27:28

标签: list interpolation terraform

我想知道是否有可能获得一个地形列表的总数,我已经查看了tf网站,并且没有看到任何总计数只是使用count.index。

示例列表

var "testList"
type = "list"

default [
{
  type = "test1"
},
{
  type = "test2"
}
]

所以在这里我希望得到2作为测试列表的总数

由于

1 个答案:

答案 0 :(得分:2)

您可以使用terraform内置函数length()来获取计数。

count = "${length(var.testList)}"

详情请参阅terraform文件:

terraform length list