@@ -3,10 +3,14 @@ resource "aws_acm_certificate" "default" {
3
3
validation_method = " ${ var . validation_method } "
4
4
subject_alternative_names = [" ${ var . subject_alternative_names } " ]
5
5
tags = " ${ var . tags } "
6
+
7
+ lifecycle {
8
+ create_before_destroy = true
9
+ }
6
10
}
7
11
8
12
data "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 } "
10
14
name = " ${ var . domain_name } ."
11
15
private_zone = false
12
16
}
@@ -15,11 +19,25 @@ locals {
15
19
domain_validation_options = " ${ aws_acm_certificate . default . domain_validation_options [0 ]} "
16
20
}
17
21
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
+
18
36
resource "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 ) } "
20
38
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" ) } "
23
41
ttl = " ${ var . ttl } "
24
- records = [" ${ local . domain_validation_options [ " resource_record_value" ] } " ]
42
+ records = [" ${ lookup ( " null_resource.default. ${ count . index } " , " resource_record_value" ) } " ]
25
43
}
0 commit comments