Loop iam 资源地形
Loop iam resources terraform
我正在尝试在 aws_iam_policy_document
语句的 resources
块内创建一个循环。
我有一个局部变量accounts_to_protect,它是 AWS 账户 ID 的列表
locals {
accounts_to_protect = tolist(setsubtract(var.all_accounts, var.blocked_accounts))
}
目前,我只使用列表的第一个索引
resources = [
"arn:aws:ec2::${local.accounts_to_protect.0}:*"
]
我不知道如何在资源块中迭代它。我试图添加一个 for 但它似乎不起作用。我希望每个帐户 ID 都有一个资源 arn。
一种可能的解决方案已在评论中。第二个,将是:
resources = [for account in local.accounts_to_protect: "arn:aws:ec2::${account}:*"]
我正在尝试在 aws_iam_policy_document
语句的 resources
块内创建一个循环。
我有一个局部变量accounts_to_protect,它是 AWS 账户 ID 的列表
locals {
accounts_to_protect = tolist(setsubtract(var.all_accounts, var.blocked_accounts))
}
目前,我只使用列表的第一个索引
resources = [
"arn:aws:ec2::${local.accounts_to_protect.0}:*"
]
我不知道如何在资源块中迭代它。我试图添加一个 for 但它似乎不起作用。我希望每个帐户 ID 都有一个资源 arn。
一种可能的解决方案已在评论中。第二个,将是:
resources = [for account in local.accounts_to_protect: "arn:aws:ec2::${account}:*"]