作为当地人,我有以下清单:
person = [
{
name = "bob"
grants = [
{
principals = "[email protected]"
},
{
group = ["users"]
}
]
},
{
name = "alice"
grants = [
{
principals = "[email protected]"
}
]
}
]
我只想过滤(人)对象,这些对象在 grants 中至少有一个元素具有 attribute group
。因此,在示例中,对象 bob 应该保留在其中,而 alice 应该消失。
我尝试过类似的方法但没有成功
{ for b in(flatten([for person in local.persons :
[{ "p_name" = person.name, "grants" = person.grants }] if contains(keys(person.grants), "group")])) : b.p_name =>
{ "p_name" = b.p_name, "grants"=b.grants } }
使用您现有的代码,您将获得:
在您的输入中,授权是一个列表,
keys
函数需要一个映射或对象。为了让您的代码按原样工作,您的输入必须更改
grants
为类似以下的地图:如果您想保留现有的输入结构,那么您的 if 语句必须更改以考虑补助金中的列表,terraform 代码将如下所示: