For_each doesn't work with aws apprunner custom domain association resource

I’m getting the following error with multiple versions of terraform (including 1.1.8). Does anyone have any idea why this isn’t working?

It does work with aws_acm_certificate.domain_validation_options and the resources appear to be implemented using a similar structure.

The issue has been noted here.

│ Error: Invalid for_each argument
│
│   on main.tf line 30, in resource "aws_route53_record" "main-cert":
│   30:   for_each = {
│   31:     for entry in aws_apprunner_custom_domain_association.main.certificate_validation_records : entry.name => {
│   32:       name   = entry.name
│   33:       record = entry.value
│   34:       type   = entry.type
│   35:     }
│   36:   }
│     ├────────────────
│     │ aws_apprunner_custom_domain_association.main.certificate_validation_records is a set of object, known only after apply
│
│ 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.
1 Like