user3362856
user3362856

Reputation: 67

Get total count of list in Terraform

I am wondering if it's possible to get the total count of a list in terraform, I've looked at the tf website and don't see anything for the total count just the use of count.index.

An example list

var "testList"
type = "list"

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

So here I want to get 2 as the total count of testlist

Thanks

Upvotes: 3

Views: 5621

Answers (1)

BMW
BMW

Reputation: 45313

you can use terraform built-in function length() to get the count.

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

For details, please go through terraform documents:

terraform length list

Upvotes: 6

Related Questions