Skip to content

Commit 1a35faa

Browse files
committed
Fix ACM change every run
1 parent f14393a commit 1a35faa

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

main.tf

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
locals {
2-
all_domains = [
3-
for v in var.domains: v.domain
4-
]
5-
all_zones = [
6-
for v in var.domains: v.zone
7-
]
8-
distinct_zones = distinct([
9-
for v in var.domains: v.zone
2+
all_domains = concat([var.domain_name.domain], [
3+
for v in var.subject_alternative_names: v.domain
4+
])
5+
all_zones = concat([var.domain_name.zone], [
6+
for v in var.subject_alternative_names: v.zone
107
])
8+
distinct_zones = distinct(local.all_zones)
119
distinct_domains = distinct([
1210
for domain in local.all_domains: replace(domain, "*.", "")
1311
])
1412
zone_name_to_id_map = zipmap(local.distinct_zones, data.aws_route53_zone.self[*].zone_id)
1513
domain_to_zone_map = zipmap(local.all_domains, local.all_zones)
1614

17-
cert_domain_name = sort(local.all_domains)[0]
18-
cert_san = slice(sort(local.all_domains), 1, length(local.all_domains))
15+
cert_san = reverse(sort([
16+
for v in var.subject_alternative_names: v.domain
17+
]))
1918
cert_validation_domains = [
2019
for v in aws_acm_certificate.self.domain_validation_options: tomap(v) if contains(local.distinct_domains, replace(v.domain_name, "*.", ""))
2120
]
@@ -29,7 +28,7 @@ data "aws_route53_zone" "self" {
2928
}
3029

3130
resource "aws_acm_certificate" "self" {
32-
domain_name = local.cert_domain_name
31+
domain_name = var.domain_name.domain
3332
subject_alternative_names = local.cert_san
3433
validation_method = "DNS"
3534

variables.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
variable "domains" {
2-
description = "List of map of string containing domain name for the certificate and its corresponding hosted zone name"
1+
variable "domain_name" {
2+
description = "Domain name for the ACM certificate"
3+
type = map(string)
4+
}
5+
6+
variable "subject_alternative_names" {
7+
description = "List of subject alternative names for the ACM certificate"
38
type = list(map(string))
49
}
510

0 commit comments

Comments
 (0)