Skip to content

Commit 40ebc5f

Browse files
Jamie-BitFlightaknysh
authored andcommitted
Added domain validation, and domain name creation for all SAN's (#6)
* Added domain validation, and domain name creation for all SAN's * removed unneeded output
1 parent b43c2b0 commit 40ebc5f

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Compiled files
2-
*.tfstate
2+
**/*.tfstate
33
*.tfstate.backup
44

55
# Module directory
6-
.terraform/
6+
**/.terraform/
77
.idea
88
*.iml
99

main.tf

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

812
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}"
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+
1836
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)}"
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
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ output "id" {
44
}
55

66
output "arn" {
7-
value = "${aws_acm_certificate.default.arn}"
7+
value = "${aws_acm_certificate_validation.default.certificate_arn}"
88
description = "The ARN of the certificate"
99
}
1010

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ variable "validation_method" {
99
description = "Which method to use for validation, DNS or EMAIL"
1010
}
1111

12-
variable "proces_domain_validation_options" {
12+
variable "process_domain_validation_options" {
1313
type = "string"
1414
default = "true"
1515
description = "Flag to enable/disable processing of the record to add to the DNS zone to complete certificate validation"

0 commit comments

Comments
 (0)