Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 861
user3362856 Avatar asked Jan 01 '26 13:01

user3362856


1 Answers

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

like image 88
BMW Avatar answered Jan 03 '26 12:01

BMW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!