@@ -13,52 +13,27 @@ resource "aws_acm_certificate" "this" {
13
13
}
14
14
15
15
locals {
16
- dvo = tolist ( aws_acm_certificate. this . domain_validation_options )[ 0 ]
16
+ dvo_list = [ for dvo in aws_acm_certificate . this . domain_validation_options : dvo ]
17
17
}
18
18
19
- # Register records to prove we own the domain name
19
+ # Conditionally create the Route 53 record (skipped if validate_route53 is false)
20
20
resource "aws_route53_record" "verify" {
21
- # Following this
22
- # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-3-upgrade#resource-aws_acm_certificate
23
- # I would expect this to work:
21
+ count = var. validate_route53 ? length (local. dvo_list ) : 0
24
22
25
- # for_each = {
26
- # for dvo in aws_acm_certificate.this.domain_validation_options : dvo.domain_name => {
27
- # name = dvo.resource_record_name
28
- # record = dvo.resource_record_value
29
- # type = dvo.resource_record_type
30
- # }
31
- # }
32
-
33
- # name = each.value.name
34
- # records = [each.value.record]
35
- # type = each.value.type
36
- # zone_id = var.zone_id
37
- # ttl = 60
38
-
39
- # But it doesn't, so I just copied https://github.com/terraform-providers/terraform-provider-aws/issues/14447
40
- name = local. dvo . resource_record_name
41
- records = [local . dvo . resource_record_value ]
42
- type = local. dvo . resource_record_type
23
+ name = local. dvo_list [count . index ]. resource_record_name
24
+ records = [local . dvo_list [count . index ]. resource_record_value ]
25
+ type = local. dvo_list [count . index ]. resource_record_type
43
26
zone_id = var. zone_id
44
27
ttl = 60
45
28
}
46
29
47
- # Wait for the certificate to be issued
30
+ # Create the certificate validation, even if Route 53 records are not created
48
31
resource "aws_acm_certificate_validation" "this" {
49
32
certificate_arn = aws_acm_certificate. this . arn
50
- # validation_record_fqdns = [for record in aws_route53_record.verify : record.fqdn]
51
- validation_record_fqdns = aws_route53_record. verify [* ]. fqdn
33
+
34
+ validation_record_fqdns = var . validate_route53 ? aws_route53_record. verify [* ]. name : [ for dvo in local . dvo_list : dvo . resource_record_name ]
52
35
}
53
36
54
37
output "arn" {
55
- # Output the certificate only once it has been validated.
56
- #
57
- # Otherwise, Terraform may try to feed the certificate ARN to another
58
- # resource (such as a load-balancer listener), which may be rejected because
59
- # the certificate is not valid:
60
- #
61
- # UnsupportedCertificate: The certificate 'XXX' must have a fully-qualified
62
- # domain name, a supported signature, and a supported key size.
63
38
value = aws_acm_certificate_validation. this . certificate_arn
64
39
}
0 commit comments