Last active
May 26, 2023 20:29
-
-
Save arehmandev/f963272fd766fcfa176fea029f3c5359 to your computer and use it in GitHub Desktop.
Terraform nested for loop for_each
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for_each nested loop using setproduct and using raw iteration with for | |
locals { | |
list1 = ["1", "2", "3"] | |
list2 = ["a", "b", "c"] | |
list3 = ["4", "5", "6"] | |
list4 = ["d", "e", "f"] | |
nested_loop = { for k in setproduct(local.list1, local.list2, local.list3, local.list4) : | |
"${k[0]}-${k[1]}-${k[2]}-${k[3]}" => { "1" : k[0], "2" : k[1], "3" : k[2], "4" : k[3] } | |
} | |
nested_loop2 = { for entry in flatten(values({ | |
for k in local.list1 : | |
k => [for v in local.list2 : [ | |
for y in local.list3 : [ | |
for z in local.list4 : [ | |
{ "${k}-${v}-${y}-${z}" : { "1" : k, "2" : v, "3" : y, "4" : z } } | |
]]]] })) : | |
keys(entry)[0] => values(entry)[0] | |
} | |
} | |
output "map_output" { | |
value = local.nested_loop | |
} | |
output "map_output2" { | |
value = local.nested_loop2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.[0m | |
Outputs: | |
map_output = { | |
"1-a-4-d" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "4" | |
"4" = "d" | |
} | |
"1-a-4-e" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "4" | |
"4" = "e" | |
} | |
"1-a-4-f" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "4" | |
"4" = "f" | |
} | |
"1-a-5-d" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "5" | |
"4" = "d" | |
} | |
"1-a-5-e" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "5" | |
"4" = "e" | |
} | |
"1-a-5-f" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "5" | |
"4" = "f" | |
} | |
"1-a-6-d" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "6" | |
"4" = "d" | |
} | |
"1-a-6-e" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "6" | |
"4" = "e" | |
} | |
"1-a-6-f" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "6" | |
"4" = "f" | |
} | |
"1-b-4-d" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "4" | |
"4" = "d" | |
} | |
"1-b-4-e" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "4" | |
"4" = "e" | |
} | |
"1-b-4-f" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "4" | |
"4" = "f" | |
} | |
"1-b-5-d" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "5" | |
"4" = "d" | |
} | |
"1-b-5-e" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "5" | |
"4" = "e" | |
} | |
"1-b-5-f" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "5" | |
"4" = "f" | |
} | |
"1-b-6-d" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "6" | |
"4" = "d" | |
} | |
"1-b-6-e" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "6" | |
"4" = "e" | |
} | |
"1-b-6-f" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "6" | |
"4" = "f" | |
} | |
"1-c-4-d" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "4" | |
"4" = "d" | |
} | |
"1-c-4-e" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "4" | |
"4" = "e" | |
} | |
"1-c-4-f" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "4" | |
"4" = "f" | |
} | |
"1-c-5-d" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "5" | |
"4" = "d" | |
} | |
"1-c-5-e" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "5" | |
"4" = "e" | |
} | |
"1-c-5-f" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "5" | |
"4" = "f" | |
} | |
"1-c-6-d" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "6" | |
"4" = "d" | |
} | |
"1-c-6-e" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "6" | |
"4" = "e" | |
} | |
"1-c-6-f" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "6" | |
"4" = "f" | |
} | |
"2-a-4-d" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "4" | |
"4" = "d" | |
} | |
"2-a-4-e" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "4" | |
"4" = "e" | |
} | |
"2-a-4-f" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "4" | |
"4" = "f" | |
} | |
"2-a-5-d" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "5" | |
"4" = "d" | |
} | |
"2-a-5-e" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "5" | |
"4" = "e" | |
} | |
"2-a-5-f" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "5" | |
"4" = "f" | |
} | |
"2-a-6-d" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "6" | |
"4" = "d" | |
} | |
"2-a-6-e" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "6" | |
"4" = "e" | |
} | |
"2-a-6-f" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "6" | |
"4" = "f" | |
} | |
"2-b-4-d" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "4" | |
"4" = "d" | |
} | |
"2-b-4-e" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "4" | |
"4" = "e" | |
} | |
"2-b-4-f" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "4" | |
"4" = "f" | |
} | |
"2-b-5-d" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "5" | |
"4" = "d" | |
} | |
"2-b-5-e" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "5" | |
"4" = "e" | |
} | |
"2-b-5-f" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "5" | |
"4" = "f" | |
} | |
"2-b-6-d" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "6" | |
"4" = "d" | |
} | |
"2-b-6-e" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "6" | |
"4" = "e" | |
} | |
"2-b-6-f" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "6" | |
"4" = "f" | |
} | |
"2-c-4-d" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "4" | |
"4" = "d" | |
} | |
"2-c-4-e" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "4" | |
"4" = "e" | |
} | |
"2-c-4-f" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "4" | |
"4" = "f" | |
} | |
"2-c-5-d" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "5" | |
"4" = "d" | |
} | |
"2-c-5-e" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "5" | |
"4" = "e" | |
} | |
"2-c-5-f" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "5" | |
"4" = "f" | |
} | |
"2-c-6-d" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "6" | |
"4" = "d" | |
} | |
"2-c-6-e" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "6" | |
"4" = "e" | |
} | |
"2-c-6-f" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "6" | |
"4" = "f" | |
} | |
"3-a-4-d" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "4" | |
"4" = "d" | |
} | |
"3-a-4-e" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "4" | |
"4" = "e" | |
} | |
"3-a-4-f" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "4" | |
"4" = "f" | |
} | |
"3-a-5-d" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "5" | |
"4" = "d" | |
} | |
"3-a-5-e" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "5" | |
"4" = "e" | |
} | |
"3-a-5-f" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "5" | |
"4" = "f" | |
} | |
"3-a-6-d" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "6" | |
"4" = "d" | |
} | |
"3-a-6-e" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "6" | |
"4" = "e" | |
} | |
"3-a-6-f" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "6" | |
"4" = "f" | |
} | |
"3-b-4-d" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "4" | |
"4" = "d" | |
} | |
"3-b-4-e" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "4" | |
"4" = "e" | |
} | |
"3-b-4-f" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "4" | |
"4" = "f" | |
} | |
"3-b-5-d" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "5" | |
"4" = "d" | |
} | |
"3-b-5-e" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "5" | |
"4" = "e" | |
} | |
"3-b-5-f" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "5" | |
"4" = "f" | |
} | |
"3-b-6-d" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "6" | |
"4" = "d" | |
} | |
"3-b-6-e" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "6" | |
"4" = "e" | |
} | |
"3-b-6-f" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "6" | |
"4" = "f" | |
} | |
"3-c-4-d" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "4" | |
"4" = "d" | |
} | |
"3-c-4-e" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "4" | |
"4" = "e" | |
} | |
"3-c-4-f" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "4" | |
"4" = "f" | |
} | |
"3-c-5-d" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "5" | |
"4" = "d" | |
} | |
"3-c-5-e" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "5" | |
"4" = "e" | |
} | |
"3-c-5-f" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "5" | |
"4" = "f" | |
} | |
"3-c-6-d" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "6" | |
"4" = "d" | |
} | |
"3-c-6-e" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "6" | |
"4" = "e" | |
} | |
"3-c-6-f" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "6" | |
"4" = "f" | |
} | |
} | |
map_output2 = { | |
"1-a-4-d" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "4" | |
"4" = "d" | |
} | |
"1-a-4-e" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "4" | |
"4" = "e" | |
} | |
"1-a-4-f" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "4" | |
"4" = "f" | |
} | |
"1-a-5-d" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "5" | |
"4" = "d" | |
} | |
"1-a-5-e" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "5" | |
"4" = "e" | |
} | |
"1-a-5-f" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "5" | |
"4" = "f" | |
} | |
"1-a-6-d" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "6" | |
"4" = "d" | |
} | |
"1-a-6-e" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "6" | |
"4" = "e" | |
} | |
"1-a-6-f" = { | |
"1" = "1" | |
"2" = "a" | |
"3" = "6" | |
"4" = "f" | |
} | |
"1-b-4-d" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "4" | |
"4" = "d" | |
} | |
"1-b-4-e" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "4" | |
"4" = "e" | |
} | |
"1-b-4-f" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "4" | |
"4" = "f" | |
} | |
"1-b-5-d" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "5" | |
"4" = "d" | |
} | |
"1-b-5-e" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "5" | |
"4" = "e" | |
} | |
"1-b-5-f" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "5" | |
"4" = "f" | |
} | |
"1-b-6-d" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "6" | |
"4" = "d" | |
} | |
"1-b-6-e" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "6" | |
"4" = "e" | |
} | |
"1-b-6-f" = { | |
"1" = "1" | |
"2" = "b" | |
"3" = "6" | |
"4" = "f" | |
} | |
"1-c-4-d" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "4" | |
"4" = "d" | |
} | |
"1-c-4-e" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "4" | |
"4" = "e" | |
} | |
"1-c-4-f" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "4" | |
"4" = "f" | |
} | |
"1-c-5-d" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "5" | |
"4" = "d" | |
} | |
"1-c-5-e" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "5" | |
"4" = "e" | |
} | |
"1-c-5-f" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "5" | |
"4" = "f" | |
} | |
"1-c-6-d" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "6" | |
"4" = "d" | |
} | |
"1-c-6-e" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "6" | |
"4" = "e" | |
} | |
"1-c-6-f" = { | |
"1" = "1" | |
"2" = "c" | |
"3" = "6" | |
"4" = "f" | |
} | |
"2-a-4-d" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "4" | |
"4" = "d" | |
} | |
"2-a-4-e" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "4" | |
"4" = "e" | |
} | |
"2-a-4-f" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "4" | |
"4" = "f" | |
} | |
"2-a-5-d" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "5" | |
"4" = "d" | |
} | |
"2-a-5-e" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "5" | |
"4" = "e" | |
} | |
"2-a-5-f" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "5" | |
"4" = "f" | |
} | |
"2-a-6-d" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "6" | |
"4" = "d" | |
} | |
"2-a-6-e" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "6" | |
"4" = "e" | |
} | |
"2-a-6-f" = { | |
"1" = "2" | |
"2" = "a" | |
"3" = "6" | |
"4" = "f" | |
} | |
"2-b-4-d" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "4" | |
"4" = "d" | |
} | |
"2-b-4-e" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "4" | |
"4" = "e" | |
} | |
"2-b-4-f" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "4" | |
"4" = "f" | |
} | |
"2-b-5-d" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "5" | |
"4" = "d" | |
} | |
"2-b-5-e" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "5" | |
"4" = "e" | |
} | |
"2-b-5-f" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "5" | |
"4" = "f" | |
} | |
"2-b-6-d" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "6" | |
"4" = "d" | |
} | |
"2-b-6-e" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "6" | |
"4" = "e" | |
} | |
"2-b-6-f" = { | |
"1" = "2" | |
"2" = "b" | |
"3" = "6" | |
"4" = "f" | |
} | |
"2-c-4-d" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "4" | |
"4" = "d" | |
} | |
"2-c-4-e" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "4" | |
"4" = "e" | |
} | |
"2-c-4-f" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "4" | |
"4" = "f" | |
} | |
"2-c-5-d" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "5" | |
"4" = "d" | |
} | |
"2-c-5-e" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "5" | |
"4" = "e" | |
} | |
"2-c-5-f" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "5" | |
"4" = "f" | |
} | |
"2-c-6-d" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "6" | |
"4" = "d" | |
} | |
"2-c-6-e" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "6" | |
"4" = "e" | |
} | |
"2-c-6-f" = { | |
"1" = "2" | |
"2" = "c" | |
"3" = "6" | |
"4" = "f" | |
} | |
"3-a-4-d" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "4" | |
"4" = "d" | |
} | |
"3-a-4-e" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "4" | |
"4" = "e" | |
} | |
"3-a-4-f" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "4" | |
"4" = "f" | |
} | |
"3-a-5-d" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "5" | |
"4" = "d" | |
} | |
"3-a-5-e" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "5" | |
"4" = "e" | |
} | |
"3-a-5-f" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "5" | |
"4" = "f" | |
} | |
"3-a-6-d" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "6" | |
"4" = "d" | |
} | |
"3-a-6-e" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "6" | |
"4" = "e" | |
} | |
"3-a-6-f" = { | |
"1" = "3" | |
"2" = "a" | |
"3" = "6" | |
"4" = "f" | |
} | |
"3-b-4-d" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "4" | |
"4" = "d" | |
} | |
"3-b-4-e" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "4" | |
"4" = "e" | |
} | |
"3-b-4-f" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "4" | |
"4" = "f" | |
} | |
"3-b-5-d" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "5" | |
"4" = "d" | |
} | |
"3-b-5-e" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "5" | |
"4" = "e" | |
} | |
"3-b-5-f" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "5" | |
"4" = "f" | |
} | |
"3-b-6-d" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "6" | |
"4" = "d" | |
} | |
"3-b-6-e" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "6" | |
"4" = "e" | |
} | |
"3-b-6-f" = { | |
"1" = "3" | |
"2" = "b" | |
"3" = "6" | |
"4" = "f" | |
} | |
"3-c-4-d" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "4" | |
"4" = "d" | |
} | |
"3-c-4-e" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "4" | |
"4" = "e" | |
} | |
"3-c-4-f" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "4" | |
"4" = "f" | |
} | |
"3-c-5-d" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "5" | |
"4" = "d" | |
} | |
"3-c-5-e" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "5" | |
"4" = "e" | |
} | |
"3-c-5-f" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "5" | |
"4" = "f" | |
} | |
"3-c-6-d" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "6" | |
"4" = "d" | |
} | |
"3-c-6-e" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "6" | |
"4" = "e" | |
} | |
"3-c-6-f" = { | |
"1" = "3" | |
"2" = "c" | |
"3" = "6" | |
"4" = "f" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment