Created
August 12, 2021 06:45
-
-
Save arehmandev/bbcac2aac066d8529cc5a185361ac3ab to your computer and use it in GitHub Desktop.
Nested surfacing dict
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
locals { | |
input = { | |
"projects" : { | |
"another" : { | |
"accounts" : [ | |
"one", | |
"two" | |
] | |
}, | |
"test" : { | |
"accounts" : [ | |
"test", | |
"hello" | |
] | |
} | |
} | |
} | |
test = { for v in flatten([for _, v in local.input : | |
[for x, y in v : [for a in y.accounts : { "${a}" : x }]] | |
]) : | |
keys(v)[0] => values(v)[0] | |
} | |
# Apply complete! Resources: 0 added, 0 changed, 0 destroyed. | |
# Outputs: | |
# test = { | |
# "hello" = "test" | |
# "one" = "another" | |
# "test" = "test" | |
# "two" = "another" | |
# } | |
} | |
output "test" { | |
value = local.test | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment