【发布时间】:2020-10-20 04:28:09
【问题描述】:
我在 terraform 中有一个地图,其中键是字符串,值是字符串列表。它看起来像:
locals {
admin_account_ids_by_team_name = {
"foobar" = ["12345", "67890"]
}
}
我需要将其转换为:
{
"foobar-12345" = { account_id = "12345", team_name = "foobar" }
"foobar-67890" = { account_id = "67890", team_name = "foobar" }
}
在terraform console 中玩耍我已经能够使用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})]]) 获得一些接近的东西
然而这给了我:
[
{
"12345-foobar" = {
"account_id" = "12345"
"team" = "foobar"
}
},
{
"67890-foobar" = {
"account_id" = "67890"
"team" = "foobar"
}
},
]
【问题讨论】:
-
如果这些值被硬编码到你的本地,你也可以总是硬编码其他的
map。结构转换对于动态输入变量更有用。
标签: terraform