mediapop / terraform-aws-certificate

Simple way of creating validated certs over multiple domains and zones.
MIT License
3 stars 6 forks source link

Error: Invalid for_each argument when using more than one needed DNs #2

Open frozeneyemr opened 2 years ago

frozeneyemr commented 2 years ago

Hi,

I'm not able to use more than one source aliases for the redirect like shown in the default example. "mediapopinc.com." = ["mediapopinc.com", "www.mediapopinc.com"] This is failing with following error:

Error: Invalid for_each argument
│ 
│   on .terraform/modules/redirect0.certificate/main.tf line 26, in resource "aws_route53_record" "record":
│   26:   for_each = {
│   27:     // Asking for aws_acm_certificate.cert.0 will raise an exception when no certificate is being setup.
│   28:     for dvo in flatten(aws_acm_certificate.cert.*.domain_validation_options) : dvo.domain_name => {
│   29:       name  = dvo.resource_record_name
│   30:       value = dvo.resource_record_value
│   31:       type  = dvo.resource_record_type
│   32:       zone_id = data.aws_route53_zone.zone[local.host_to_zone[dvo.domain_name]].zone_id
│   33:     }
│   34:   }
│     ├────────────────
│     │ aws_acm_certificate.cert is tuple with 1 element
│     │ data.aws_route53_zone.zone is object with 1 attribute "awstest.adesso-test.de."
│     │ local.host_to_zone is object with 2 attributes
│ 
│ The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target
│ argument to first apply only the resources that the for_each depends on.

Version Info:

$ terraform --version                                                                                                                                                                    Terraform v1.0.9
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.63.0

It's working only with one entry behind the domain, f.eg. "mediapopinc.com." = ["mediapopinc.com"]

I've also tried to apply with target option for different ressources but with no success. Any ideas? Thanks!

frozeneyemr commented 2 years ago

3 fixes this issue