获取Terraform中的列表总数

问题描述 投票:1回答:1

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

示例列表

var "testList"
type = "list"

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

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

谢谢

list interpolation terraform
1个回答
2
投票

你可以使用terraform内置函数length()来计算。

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

有关详细信息,请查看terraform文档:

terraform length list

© www.soinside.com 2019 - 2024. All rights reserved.