Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Created August 12, 2021 06:45
Show Gist options
  • Save arehmandev/bbcac2aac066d8529cc5a185361ac3ab to your computer and use it in GitHub Desktop.
Save arehmandev/bbcac2aac066d8529cc5a185361ac3ab to your computer and use it in GitHub Desktop.
Nested surfacing dict
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