array.map like function in terraform

Viewed 140

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?

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,
]
Related