rahuljain1311
rahuljain1311

Reputation: 2160

Merge elements from different lists in terraform 0.12

I am trying to create a list of maps from two different lists in terraform 0.12

E.g.

List1: ["a", "b", "c"]

List2: ["aa", "bb", "cc"]

Output required:

[{
"list1element" = "a"
"list2element" = "aa"
}, {
"list1element" = "b"
"list2element" = "bb"
}, {
"list1element" = "c"
"list2element" = "cc"
}]

If I could get the index of the element in the loop this would be so easy. Nested loops also make no sense.

Upvotes: 0

Views: 532

Answers (1)

Martin Atkins
Martin Atkins

Reputation: 74064

If you know that the two lists will always have the same length, you can use the indices from one list with the other list:

[for i, v in list1 : {
  list1element = list1[i]
  list2element = list2[i]
}]

Upvotes: 1

Related Questions