forked from cloudposse/terraform-aws-acm-request-certificate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
44 lines (36 loc) · 1.67 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
resource "aws_acm_certificate" "default" {
domain_name = "${var.domain_name}"
validation_method = "${var.validation_method}"
subject_alternative_names = ["${var.subject_alternative_names}"]
tags = "${var.tags}"
lifecycle {
create_before_destroy = true
}
}
data "aws_route53_zone" "default" {
count = "${var.process_domain_validation_options == "true" && var.validation_method == "DNS" ? 1 : 0}"
name = "${local.zone_name}."
private_zone = false
}
locals {
domain_validation_options = "${aws_acm_certificate.default.domain_validation_options[0]}"
zone_name = "${var.zone_name == "" ? var.domain_name : var.zone_name}"
}
resource "null_resource" "default" {
count = "${var.process_domain_validation_options == "true" && var.validation_method == "DNS" ? length(aws_acm_certificate.default.domain_validation_options) : 0}"
triggers = "${aws_acm_certificate.default.domain_validation_options[count.index]}"
}
resource "aws_acm_certificate_validation" "default" {
certificate_arn = "${aws_acm_certificate.default.arn}"
validation_record_fqdns = [
"${distinct(compact(concat(aws_route53_record.default.fqdn, var.subject_alternative_names)))}",
]
}
resource "aws_route53_record" "default" {
count = "${length(null_resource.default.triggers)}"
zone_id = "${data.aws_route53_zone.default.zone_id}"
name = "${lookup("null_resource.default.${count.index}","resource_record_name")}"
type = "${lookup("null_resource.default.${count.index}", "resource_record_type")}"
ttl = "${var.ttl}"
records = ["${lookup("null_resource.default.${count.index}","resource_record_value")}"]
}