Skip to content

Commit 2eec7e5

Browse files
Allow management of ACM certs with SANs in multiple zones (cloudposse#61)
* Allow multiple zones * Auto Format * Fix syntax error * Use local.all_domains instead of unused locals * test: use domain without subdomain * Use parent_zone_name and prefix zone name instead * Remove multiple zone names from test * Update main.tf * Use zone_name Co-authored-by: cloudpossebot <[email protected]>
1 parent 32f16fe commit 2eec7e5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Diff for: main.tf

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
locals {
22
enabled = module.this.enabled
3-
zone_name = var.zone_name == "" ? "${var.domain_name}." : var.zone_name
43
process_domain_validation_options = local.enabled && var.process_domain_validation_options && var.validation_method == "DNS"
54
domain_validation_options_set = local.process_domain_validation_options ? aws_acm_certificate.default.0.domain_validation_options : toset([])
65
public_enabled = var.certificate_authority_arn == null
76
private_enabled = ! local.public_enabled
7+
8+
all_domains = concat(
9+
[var.domain_name],
10+
var.subject_alternative_names
11+
)
12+
domain_to_zone = {
13+
for domain in local.all_domains :
14+
domain => join(".", slice(split(".", domain), 1, length(split(".", domain))))
15+
}
16+
unique_zones = distinct(values(local.domain_to_zone))
817
}
918

1019
resource "aws_acm_certificate" "default" {
@@ -27,9 +36,9 @@ resource "aws_acm_certificate" "default" {
2736
}
2837

2938
data "aws_route53_zone" "default" {
30-
count = local.process_domain_validation_options ? 1 : 0
39+
for_each = local.process_domain_validation_options ? toset(local.unique_zones) : toset([])
3140
zone_id = var.zone_id
32-
name = try(length(var.zone_id), 0) == 0 ? local.zone_name : null
41+
name = try(length(var.zone_id), 0) == 0 ? (var.zone_name == "" ? each.key : var.zone_name) : null
3342
private_zone = local.private_enabled
3443
}
3544

@@ -41,7 +50,7 @@ resource "aws_route53_record" "default" {
4150
type = dvo.resource_record_type
4251
}
4352
}
44-
zone_id = join("", data.aws_route53_zone.default.*.zone_id)
53+
zone_id = data.aws_route53_zone.default[local.domain_to_zone[each.key]].id
4554
ttl = var.ttl
4655
allow_overwrite = true
4756
name = each.value.name

0 commit comments

Comments
 (0)