Reading about the splat operator the following should work when setting the es_domains variable in the policy section:
data "aws_elasticsearch_domain" "all" {
for_each = toset(local.es_domains)
domain_name = each.key
}
resource "aws_iam_policy" "monitoring_collector_es" {
name = "tf-monitoring_es"
description = "Used by monitoring to connect to ES"
policy = templatefile(
"${path.module}/templates/role_policy_collector_es.json.tpl",
{
role = aws_iam_role.monitoring_collector
es_domains = data.aws_elasticsearch_domain.all[*].arn
}
)
}
but results in
Error: Unsupported attribute
on ec2_collectors_iam.tf line 61, in resource "aws_iam_policy" "monitoring_collector_es":
61: es_domains = data.aws_elasticsearch_domain.all[*].arn
This object does not have an attribute named "arn".
if the es_domains is set to
es_domains = [for d in data.aws_elasticsearch_domain.all : d.arn]
it works as expected. bug? Terraform v0.14.6