Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array.map like function in terraform

Tags:

terraform

I want to map a list of object in terraform to get a list of single values.

In javascript this would look something like this.

[{a: 1}, {a: 2}].map(item => item.a)
// [1, 2]

How can I do this in terraform?

like image 602
The Fool Avatar asked Oct 25 '25 04:10

The Fool


1 Answers

locals {
  items = [for item in [{a: 1}, {a: 2}]: item.a]
}

If we output local.items we get the following:

items = [
  1,
  2,
]
like image 185
Ervin Szilagyi Avatar answered Oct 27 '25 02:10

Ervin Szilagyi



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!