Skip to content

Commit b99eae8

Browse files
committed
Fix missing certificate domain validation
1 parent 0422846 commit b99eae8

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

main.tf

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
locals {
22
all_domains = concat([var.domain_name.domain], [
3-
for v in var.subject_alternative_names: v.domain
3+
for v in var.subject_alternative_names : v.domain
44
])
55
all_zones = concat([var.domain_name.zone], [
6-
for v in var.subject_alternative_names: v.zone
7-
])
8-
distinct_zones = distinct(local.all_zones)
9-
distinct_domains = distinct([
10-
for domain in local.all_domains: replace(domain, "*.", "")
6+
for v in var.subject_alternative_names : v.zone
117
])
8+
distinct_zones = distinct(local.all_zones)
129
zone_name_to_id_map = zipmap(local.distinct_zones, data.aws_route53_zone.self[*].zone_id)
13-
domain_to_zone_map = zipmap(local.all_domains, local.all_zones)
10+
domain_to_zone_map = zipmap(local.all_domains, local.all_zones)
1411

1512
cert_san = reverse(sort([
16-
for v in var.subject_alternative_names: v.domain
13+
for v in var.subject_alternative_names : v.domain
1714
]))
1815
cert_validation_domains = [
19-
for v in aws_acm_certificate.self.domain_validation_options: tomap(v) if contains(local.distinct_domains, replace(v.domain_name, "*.", ""))
16+
for v in aws_acm_certificate.self.domain_validation_options : tomap(v)
2017
]
2118
}
2219

2320
data "aws_route53_zone" "self" {
2421
count = length(local.distinct_zones)
2522

26-
name = local.distinct_zones[count.index]
23+
name = local.distinct_zones[count.index]
2724
private_zone = false
2825
}
2926

3027
resource "aws_acm_certificate" "self" {
31-
domain_name = var.domain_name.domain
28+
domain_name = var.domain_name.domain
3229
subject_alternative_names = local.cert_san
33-
validation_method = "DNS"
30+
validation_method = "DNS"
3431

3532
tags = var.tags
3633

@@ -43,8 +40,8 @@ resource "aws_acm_certificate" "self" {
4340
}
4441

4542
resource "aws_route53_record" "validation" {
46-
count = var.validation_set_records ? length(local.distinct_domains) : 0
47-
43+
count = var.validation_set_records ? length(local.cert_validation_domains) : 0
44+
4845
zone_id = lookup(local.zone_name_to_id_map, lookup(local.domain_to_zone_map, local.cert_validation_domains[count.index]["domain_name"]))
4946
name = local.cert_validation_domains[count.index]["resource_record_name"]
5047
type = local.cert_validation_domains[count.index]["resource_record_type"]

outputs.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ output "certificate_arn" {
44
}
55

66
output "certificate_domains" {
7-
description = "List of domain names covered by the certificate"
8-
value = concat([aws_acm_certificate.self.domain_name], aws_acm_certificate.self.subject_alternative_names)
7+
description = "List of domain names covered by the certificate"
8+
value = concat([aws_acm_certificate.self.domain_name], aws_acm_certificate.self.subject_alternative_names)
99
}
1010

1111
output "certificate_domain_validation_options" {

variables.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
variable "domain_name" {
22
description = "Domain name for the ACM certificate"
3-
type = map(string)
3+
type = map(string)
44
}
55

66
variable "subject_alternative_names" {
77
description = "List of subject alternative names for the ACM certificate"
8-
type = list(map(string))
8+
type = list(map(string))
99
}
1010

1111
variable "tags" {
1212
description = "Key and value pair that will be added as tag"
13-
type = map(string)
14-
default = {}
13+
type = map(string)
14+
default = {}
1515
}
1616

1717
variable "validate_certificate" {
@@ -22,8 +22,8 @@ variable "validate_certificate" {
2222

2323
variable "validation_set_records" {
2424
description = "Whether to configure Route53 records for validation"
25-
type = bool
26-
default = true
25+
type = bool
26+
default = true
2727
}
2828

2929
variable "validation_allow_overwrite_records" {

versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
terraform {
2-
required_version = ">= 0.12.0"
2+
required_version = ">= 0.12.0"
33
}

0 commit comments

Comments
 (0)