Skip to content

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

Description

@frozeneyemr

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions