You can use terraform transpose() function to swap the keys and values of a map. transpose() takes a map of lists of strings and swaps the keys and values to produce a new map of lists of strings.
Syntax: transpose(map)
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## Open terraform console terraform console ## Swap the keys and values of a map transpose({"a" = ["1", "2"], "b" = ["2", "3"]}) ## returns ## { ## "1" = [ ## "a", ## ], ## "2" = [ ## "a", ## "b", ## ], ## "3" = [ ## "b", ## ], ## } |