Skip to content

Commit aa39efe

Browse files
authored
fix: multi region certs route53 verify records (#25)
* fix: multi region certs route53 verify records * fix: using variable already exists * fix: error for for_each * fix: final touch so validate acm but not create route53 record
1 parent ee4d6c0 commit aa39efe

File tree

2 files changed

+14
-34
lines changed

2 files changed

+14
-34
lines changed

main.tf

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,27 @@ resource "aws_acm_certificate" "this" {
1313
}
1414

1515
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]
1717
}
1818

19-
# Register records to prove we own the domain name
19+
# Conditionally create the Route 53 record (skipped if validate_route53 is false)
2020
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
2422

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
4326
zone_id = var.zone_id
4427
ttl = 60
4528
}
4629

47-
# Wait for the certificate to be issued
30+
# Create the certificate validation, even if Route 53 records are not created
4831
resource "aws_acm_certificate_validation" "this" {
4932
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]
5235
}
5336

5437
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.
6338
value = aws_acm_certificate_validation.this.certificate_arn
6439
}

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ See https://docs.aws.amazon.com/acm/latest/userguide/acm-concepts.html#concept-t
1818
EOF
1919
default = true
2020
}
21+
22+
variable "validate_route53" {
23+
type = bool
24+
default = true
25+
}

0 commit comments

Comments
 (0)