@@ -3,10 +3,14 @@ resource "aws_acm_certificate" "default" {
33 validation_method = " ${ var . validation_method } "
44 subject_alternative_names = [" ${ var . subject_alternative_names } " ]
55 tags = " ${ var . tags } "
6+
7+ lifecycle {
8+ create_before_destroy = true
9+ }
610}
711
812data "aws_route53_zone" "default" {
9- count = " ${ var . proces_domain_validation_options == " true" && var . validation_method == " DNS" ? 1 : 0 } "
13+ count = " ${ var . process_domain_validation_options == " true" && var . validation_method == " DNS" ? 1 : 0 } "
1014 name = " ${ var . domain_name } ."
1115 private_zone = false
1216}
@@ -15,11 +19,25 @@ locals {
1519 domain_validation_options = " ${ aws_acm_certificate . default . domain_validation_options [0 ]} "
1620}
1721
22+ resource "null_resource" "default" {
23+ count = " ${ var . process_domain_validation_options == " true" && var . validation_method == " DNS" ? length (aws_acm_certificate. default . domain_validation_options ) : 0 } "
24+
25+ triggers = " ${ aws_acm_certificate . default . domain_validation_options [count . index ]} "
26+ }
27+
28+ resource "aws_acm_certificate_validation" "default" {
29+ certificate_arn = " ${ aws_acm_certificate . default . arn } "
30+
31+ validation_record_fqdns = [
32+ " ${ distinct (compact (concat (aws_route53_record. default . fqdn , var. subject_alternative_names )))} " ,
33+ ]
34+ }
35+
1836resource "aws_route53_record" "default" {
19- count = " ${ var . proces_domain_validation_options == " true " && var . validation_method == " DNS " ? 1 : 0 } "
37+ count = " ${ length (null_resource . default . triggers ) } "
2038 zone_id = " ${ data . aws_route53_zone . default . zone_id } "
21- name = " ${ local . domain_validation_options [ " resource_record_name" ] } "
22- type = " ${ local . domain_validation_options [ " resource_record_type" ] } "
39+ name = " ${ lookup ( " null_resource.default. ${ count . index } " , " resource_record_name" ) } "
40+ type = " ${ lookup ( " null_resource.default. ${ count . index } " , " resource_record_type" ) } "
2341 ttl = " ${ var . ttl } "
24- records = [" ${ local . domain_validation_options [ " resource_record_value" ] } " ]
42+ records = [" ${ lookup ( " null_resource.default. ${ count . index } " , " resource_record_value" ) } " ]
2543}
0 commit comments