File tree Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Original file line number Diff line number Diff line change
1
+ data "aws_route53_zone" "parent_zone" {
2
+ zone_id = var. r53_zone_id
3
+ private_zone = false
4
+ }
5
+
6
+ resource "aws_acm_certificate" "primary" {
7
+ domain_name = " ${ var . tenant_name } .${ data . aws_route53_zone . parent_zone . name } "
8
+ validation_method = " DNS"
9
+
10
+ subject_alternative_names = [" origin.${ var . tenant_name } .${ data . aws_route53_zone . parent_zone . name } " ]
11
+
12
+ options {
13
+ certificate_transparency_logging_preference = " ENABLED"
14
+ }
15
+
16
+ lifecycle {
17
+ create_before_destroy = true
18
+ }
19
+
20
+ tags = merge (
21
+ var. tags ,
22
+ {
23
+ Name = " ${ var . tenant_name } -primary" ,
24
+ SaaSResoure = true ,
25
+ DedicatedToTenant = true ,
26
+ },
27
+ )
28
+ }
29
+
30
+ resource "aws_route53_record" "acm_validation" {
31
+ for_each = {
32
+ for dvo in aws_acm_certificate . primary . domain_validation_options : dvo . domain_name => {
33
+ name = dvo.resource_record_name
34
+ record = dvo.resource_record_value
35
+ type = dvo.resource_record_type
36
+ }
37
+ }
38
+
39
+ allow_overwrite = true
40
+ name = each. value . name
41
+ records = [each . value . record ]
42
+ ttl = 60
43
+ type = each. value . type
44
+ zone_id = var. r53_zone_id
45
+ }
46
+
47
+ resource "aws_acm_certificate_validation" "primary" {
48
+ certificate_arn = aws_acm_certificate. primary . arn
49
+ validation_record_fqdns = [for record in aws_route53_record . acm_validation : record . fqdn ]
50
+
51
+ timeouts {
52
+ create = " 60m"
53
+ }
54
+ }
Original file line number Diff line number Diff line change
1
+ output "cert_arn" {
2
+ value = aws_acm_certificate. this . arn
3
+ }
4
+
5
+ output "cert_status" {
6
+ value = aws_acm_certificate. this . status
7
+ }
8
+
9
+ output "domain_name" {
10
+ value = aws_acm_certificate. this . domain_name
11
+ }
Original file line number Diff line number Diff line change
1
+ variable "domain_name" {
2
+ description = " The domain name to be used for the certificate"
3
+ type = string
4
+ }
5
+
6
+ variable "r53_zone_id" {
7
+ description = " Parent zone_id the certificate should be created for"
8
+ type = string
9
+ }
10
+
11
+ variable "subject_alternative_names" {
12
+ description = " List of SANs to include on the certificate, changing this after create forces a re-create"
13
+ type = list (string )
14
+ default = []
15
+ }
16
+
17
+ variable "tags" {
18
+ description = " Map of tags to provide to created resources"
19
+ type = map (string )
20
+ default = {}
21
+ }
22
+
23
+ variable "ttl" {
24
+ description = " TTL to use for R53 verification records, defaults to a short time to allow quick re-create if needed"
25
+ type = number
26
+ default = 60
27
+ }
You can’t perform that action at this time.
0 commit comments