red888
red888

Reputation: 31662

flatten a map to a list in terraform?

I have this map:

  mymap = "${
      map(
      "key1", "111111",
      "key2", "222222",
      "key3", "333333"
      )
  }"

I need it as a map for some things but for other things I just need a list of values like this:

mymap = [
  "111111","222222","333333"
]

How can I convert the map to a list and store in another variable (in locals)?

Upvotes: 5

Views: 6864

Answers (1)

Marcin Wyszynski
Marcin Wyszynski

Reputation: 2258

Is the values function something you're looking for?

Using 0.12 syntax for clarity:

locals {
  myvalues = values(local.mymap)
}

Upvotes: 14

Related Questions