I have a map in terraform where the keys are strings and the values are a list of strings. It looks something like:
locals {
admin_account_ids_by_team_name = {
"foobar" = ["12345", "67890"]
}
}
I need to transform this into something like:
{
"foobar-12345" = { account_id = "12345", team_name = "foobar" }
"foobar-67890" = { account_id = "67890", team_name = "foobar" }
}
Playing around in a terraform console I've been able to get something close using: flatten([for team, account_ids in { "foobar" = ["12345", "67890"] } : [for account_id in account_ids : map("${account_id}-${team}", { account_id = account_id, team = team})]])
This however gives me:
[
{
"12345-foobar" = {
"account_id" = "12345"
"team" = "foobar"
}
},
{
"67890-foobar" = {
"account_id" = "67890"
"team" = "foobar"
}
},
]
mapalso. Structure transformations are more useful for dynamic input variables.