获取 Terraform 中列表的总数
Get total count of list in Terraform
我想知道是否有可能在 terraform 中获取列表的总数,我查看了 tf 网站,但仅使用 count.index 就没有看到任何关于总数的信息。
示例列表
var "testList"
type = "list"
default [
{
type = "test1"
},
{
type = "test2"
}
]
所以这里我想得到2作为testlist的总数
谢谢
您可以使用 terraform built-in 函数 length()
来获取计数。
count = "${length(var.testList)}"
详情请查看terraform文档:
我想知道是否有可能在 terraform 中获取列表的总数,我查看了 tf 网站,但仅使用 count.index 就没有看到任何关于总数的信息。
示例列表
var "testList"
type = "list"
default [
{
type = "test1"
},
{
type = "test2"
}
]
所以这里我想得到2作为testlist的总数
谢谢
您可以使用 terraform built-in 函数 length()
来获取计数。
count = "${length(var.testList)}"
详情请查看terraform文档: