Open micchickenburger opened 2 months ago
seems related to actual bug in Terraform/Terraform Provider AWS:
if you know the validation options as part of your CDK code, best to generate each route53 validation record directly without iterator or foreach.
@so0k how do you know the validation options up-front if you're using DNS validation? Aren't they always random values provided by AWS that cannot be pre-assigned at creation? If it's possible to assign them, do you have any information or examples on how to do this?
I'm also using values for domain_name
that are known at plan time, yet I get the same error:
var iter = TerraformIterator.FromComplexList(cert.DomainValidationOptions, "domain_name");
var records = new Route53Record(this, "validation_record", new Route53RecordConfig
{
ForEach = iter,
ZoneId = _opts.ZoneId,
Name = iter.GetString("resource_record_name"),
Type = iter.GetString("resource_record_type"),
Records = [iter.GetString("resource_record_value")],
Ttl = 60,
AllowOverwrite = true,
});
Resulting in output:
+ resource "aws_acm_certificate" "cert" {
+ arn = (known after apply)
+ domain_name = "example.com"
+ domain_validation_options = [
+ {
+ domain_name = "example.com"
+ resource_record_name = (known after apply)
+ resource_record_type = (known after apply)
+ resource_record_value = (known after apply)
},
+ {
+ domain_name = "*.example.com"
+ resource_record_name = (known after apply)
+ resource_record_type = (known after apply)
+ resource_record_value = (known after apply)
},
]
+ id = (known after apply)
+ key_algorithm = (known after apply)
...
...
│ Error: Invalid for_each argument
│
│ on cdk.tf.json line 794, in resource.aws_route53_record.validation_record (validation_record):
│ 794: "for_each": "${{ for key, val in tolist(aws_acm_certificate.cert (cert).domain_validation_options): val.domain_name => val }}",
│ ├────────────────
│ │ aws_acm_certificate.cert.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.
The order and count can be calculated from the Subject Name and SANS
so far my integration tests always pass, so this seems consistent...
Description
Dynamic complex list iterations introduced in PR #3273 don't seem to handle sets containing more than one object. Consider a certificate request with more than one Subject Alternative Name, viz.:
This results in the following new resource:
However, the Route53 records will fail to create:
If
aws_acm_certificate.cert.domain_validation_options
is a set of one object, then the code works correctly.System information
Links
Help Wanted
Community Note