title: Create multiple unique aws_acm_certificate certificates with Terraform for_each
body: <p>I am trying to create multiple unique aws_acm_certificates using Terraform for_each,I created the acm certificates as modules for each of the unique certificate.</p>
  <p>I am having a challenge outputing the certificates created, not sure of how to output for each of the modules.</p>
  <p>This is my code. Would appreciate any help on how to create</p>
  <pre><code>locals {
    process_domain_validation_options = var.process_domain_validation_options &amp;&amp; var.acm_validation_method == &quot;DNS&quot;
  }
  
  resource &quot;aws_acm_certificate&quot; &quot;cert&quot; {
    for_each                  = var.acm_certificate
    domain_name               = each.key.domain_name
    subject_alternative_names = each.key.subject_alternative_names
    validation_method         = var.acm_validation_method
  
    lifecycle {
      create_before_destroy = true
    }
  
    tags = {
       Name = &quot;${var.tags}-var.environment&quot;
    }
  }
  
  data &quot;aws_route53_zone&quot; &quot;default&quot; {
    count        = local.process_domain_validation_options ? 1 : 0
    zone_id      = var.hosted_zone_id
    name         = try(length(var.hosted_zone_id), 0) == 0 ? var.domain_name : null
    private_zone = var.route53_private_zone
  }
  
  resource &quot;aws_route53_record&quot; &quot;cert_dns_validation&quot; {
    for_each = {
      for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name =&gt; {
        name   = dvo.resource_record_name
        record = dvo.resource_record_value
        type   = dvo.resource_record_type
      }
    }
  
    allow_overwrite = var.allow_validation_record_overwrite
    zone_id         = join(&quot;&quot;, data.aws_route53_zone.default.*.zone_id)
    ttl             = var.validation_record_ttl
    name            = each.value.name
    type            = each.value.type
    records         = [each.value.record]
  }
  
  resource &quot;aws_acm_certificate_validation&quot; &quot;default&quot; {
    count                   = local.process_domain_validation_options &amp;&amp; var.wait_for_certificate_issued ? 1 : 0
    certificate_arn         = aws_acm_certificate.cert.arn
    validation_record_fqdns = [for record in aws_route53_record.cert_dns_validation : record.fqdn]
  }
  
      variable &quot;acm_certificate&quot; {
    type      = map(object({
      domain_name = string 
      subject_alternative_names = string
    }))
    default = {
      &quot;key&quot; = {
        domain_name = &quot;value&quot;
        subject_alternative_names = &quot;value&quot;
      }
    }
  }
  </code></pre>
  <p>I'm not sure of a better way to do it.</p>