hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.88k stars 456 forks source link

COMPONENT: example for iterators on complex lists #3627

Open infowolfe opened 6 months ago

infowolfe commented 6 months ago

Description

When run, the python code linked below runs into an issue addressed in terraform!30838

[2024-05-19T14:13:19.104] [ERROR] default - ╷
│ Error: Invalid for_each argument
│
│   on cdk.tf.json line 180, in resource.aws_route53_record.redacted:
│  180:         "for_each": "${{ for key, val in tolist(aws_acm_certificate.redacted_B0655DA5.domain_validation_options): val.domain_name => val }}",
│     ├────────────────
│     │ aws_acm_certificate.redacted_B0655DA5.domain_validation_options is set of object with 2 elements
│
│ The "for_each" map includes keys derived from resource attributes that
│ cannot be determined until apply, and so Terraform cannot determine the
│ full set of keys that will identify the instances of this resource.
│
│ When working with unknown values in for_each, it's better to define the map
│ keys statically in your configuration and place apply-time results only in
│ the map values.
│
│ Alternatively, you could use the -target planning option to first apply
│ only the resources that the for_each value depends on, and then apply a
│ second time to fully converge

This is compounded by terraform-provider-aws!33613 also having invalid example code.

Links

Help Wanted

Community Note