forked from appzen-oss/terraform-aws-env-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssl-certificate.tf
77 lines (68 loc) · 3.23 KB
/
ssl-certificate.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// SSL certificate
//
resource "aws_acm_certificate" "env_wildcard" {
depends_on = ["module.domain"]
provider = "aws.member"
domain_name = "*.${var.environment}.${local.parent_zone}"
subject_alternative_names = ["*.${local.parent_zone}", "*.${var.top_level_domain}"]
validation_method = "DNS"
tags = {
Environment = "${var.environment}"
}
lifecycle {
create_before_destroy = true
}
}
locals {
alt_domains = "${list(
aws_acm_certificate.env_wildcard.domain_validation_options.0.domain_name,
aws_acm_certificate.env_wildcard.domain_validation_options.1.domain_name,
aws_acm_certificate.env_wildcard.domain_validation_options.2.domain_name
)}"
domain_env = "${index(local.alt_domains, "*.${var.environment}.${local.parent_zone}")}"
domain_parent = "${index(local.alt_domains, "*.${local.parent_zone}")}"
domain_root = "${index(local.alt_domains, "*.${var.top_level_domain}")}"
}
resource "aws_route53_record" "env_wildcard_validation" {
provider = "aws.member"
depends_on = ["aws_acm_certificate.env_wildcard"]
name = "${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_env], "resource_record_name")}"
type = "${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_env], "resource_record_type")}"
records = ["${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_env], "resource_record_value")}"]
zone_id = "${module.domain.zone_id}"
ttl = 60
}
resource "aws_route53_record" "parent_wildcard_validation" {
provider = "aws.member"
depends_on = ["aws_acm_certificate.env_wildcard"]
allow_overwrite = true
name = "${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_parent], "resource_record_name")}"
type = "${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_parent], "resource_record_type")}"
records = ["${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_parent], "resource_record_value")}"]
zone_id = "${module.domain.parent_zone_id}"
ttl = 60
}
data "aws_route53_zone" "root_domain" {
provider = "aws.root_domain"
name = "${var.top_level_domain}."
}
resource "aws_route53_record" "root_wildcard_validation" {
provider = "aws.root_domain"
depends_on = ["aws_acm_certificate.env_wildcard"]
allow_overwrite = true
name = "${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_root], "resource_record_name")}"
type = "${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_root], "resource_record_type")}"
records = ["${lookup(aws_acm_certificate.env_wildcard.domain_validation_options[local.domain_root], "resource_record_value")}"]
zone_id = "${data.aws_route53_zone.root_domain.zone_id}"
ttl = 60
}
resource "aws_acm_certificate_validation" "env_wildcard" {
provider = "aws.member"
certificate_arn = "${aws_acm_certificate.env_wildcard.arn}"
validation_record_fqdns = [
"${aws_route53_record.env_wildcard_validation.fqdn}",
"${aws_route53_record.parent_wildcard_validation.fqdn}",
"${aws_route53_record.root_wildcard_validation.fqdn}",
]
}