I can’t seem to create a loop for the Principal statement like the following due to syntax issues.
If I do slightly different and use for_each I basically end up creating 4 roles instead of just 1 role with 4 Principals
resource "aws_iam_role" "external-dns-cross-account" {
count = local.dns_account
name = "external-dns-cross-account"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
AWS = [
for ( id in module.ap-globals.ap_accounts ) {
"arn:aws:iam::${id}:role/external-dns*"·
}
]
}
Action = "sts:AssumeRole"
}
]
})
inline_policy {
name = "route53"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = "route53:*",
Resource = var.zones,
Effect = "Allow"
}
]
})
}
tags = local.tags
}