-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLT-977 added support for multi-domain certs by enabling dns validati…
…on for SANs
- Loading branch information
Showing
7 changed files
with
65 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
data "cloudflare_zone" "this" { | ||
count = var.create_certificate ? 1 : 0 | ||
name = var.zone_name | ||
for_each = { for d, p in local.domain_validation_providers : d => p if p.provider == "cloudflare" } | ||
name = each.value.zone_domain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
locals { | ||
# Get distinct list of domains and SANs | ||
distinct_domain_names = distinct( | ||
[for s in concat([var.domain_name], var.subject_alternative_names) : replace(s, "*.", "")] | ||
) | ||
# Creates a map of domains and their dns providers | ||
domain_validation_providers = { | ||
for v in concat([ | ||
[var.domain_name, var.dns_validation_provider] | ||
], var.subject_alternative_names) : v[0] => { | ||
provider = v[1] | ||
# if condition to check the root domain; flaconi.de vs www.flaconi.de | ||
zone_domain = length(split(".", v[0])) == 2 ? v[0] : regex("^.+\\.(.+\\..+)$", v[0])[0] | ||
} | ||
} | ||
|
||
# Get the list of distinct domain_validation_options, with wildcard | ||
# domain names replaced by the domain name | ||
validation_domains = var.create_certificate ? distinct( | ||
[for k, v in aws_acm_certificate.this[0].domain_validation_options : merge( | ||
tomap(v), { domain_name = replace(v.domain_name, "*.", "") } | ||
)] | ||
) : [] | ||
# Enrich domain_validation_options with their dns providers | ||
acm_domain_validation_options = var.create_certificate && var.validate_certificate ? [ | ||
for i, dvo in aws_acm_certificate.this[0].domain_validation_options : | ||
merge(dvo, { | ||
provider = local.domain_validation_providers[dvo.domain_name]["provider"] | ||
zone_domain = local.domain_validation_providers[dvo.domain_name]["zone_domain"] | ||
}) | ||
] : [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,4 @@ | ||
output "acm_certificate_arn" { | ||
description = "The ARN of the certificate" | ||
value = element(concat(aws_acm_certificate_validation.this.*.certificate_arn, aws_acm_certificate.this.*.arn, [""]), 0) | ||
} | ||
|
||
output "acm_certificate_domain_validation_options" { | ||
description = "A list of attributes to feed into other resources to complete certificate validation. Can have more than one element, e.g. if SANs are defined." | ||
value = flatten(aws_acm_certificate.this.*.domain_validation_options) | ||
} | ||
|
||
output "validation_dns_record_fqdns" { | ||
description = "List of FQDNs built using the zone domain and name." | ||
value = cloudflare_record.validation.*.hostname | ||
} | ||
|
||
output "distinct_domain_names" { | ||
description = "List of distinct domains names used for the validation." | ||
value = local.distinct_domain_names | ||
} | ||
|
||
output "validation_domains" { | ||
description = "List of distinct domain validation options. This is useful if subject alternative names contain wildcards." | ||
value = local.validation_domains | ||
value = var.create_certificate ? aws_acm_certificate.this[0].arn : null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters