I'm trying to create a loop inside the resources
bloc on a aws_iam_policy_document
statement.
I do have a local variable accounts_to_protect which is a list of AWS's account's ID
locals {
accounts_to_protect = tolist(setsubtract(var.all_accounts, var.blocked_accounts))
}
Currently, I just use the first index of my list
resources = [
"arn:aws:ec2::${local.accounts_to_protect.0}:*"
]
I don't know how I can iterate it inside the resources block. I tried to add a for but it seems to not work. I would like to have a resource arn per account id.
One possible solution is already in comments. The second one, would be:
resources = [for account in local.accounts_to_protect: "arn:aws:ec2::${account}:*"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.