From 8cf4dd9bd8708bf73b566ad3e244a2d14003e4ab Mon Sep 17 00:00:00 2001 From: Andy Singleton Date: Thu, 11 Jul 2024 22:58:44 +0100 Subject: [PATCH] Allow whitelist distributions to be stood up before certs are finalized This avoids the catch-22 of a distribution requiring a valid cname that points to it before it can be created --- aws_acm_certificates.tf | 1 + aws_cloudfront_distribution.tf | 6 ++---- outputs.tf | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/aws_acm_certificates.tf b/aws_acm_certificates.tf index 1d578df..62f4b3e 100644 --- a/aws_acm_certificates.tf +++ b/aws_acm_certificates.tf @@ -10,6 +10,7 @@ resource "aws_acm_certificate" "certificate" { } resource "aws_acm_certificate_validation" "cert" { + count = var.whitelabel_domain ? 0 : 1 provider = aws.cloudfront certificate_arn = aws_acm_certificate.certificate.arn validation_record_fqdns = [for record in aws_route53_record.certificate_validation : record.fqdn] diff --git a/aws_cloudfront_distribution.tf b/aws_cloudfront_distribution.tf index b103e67..c4cecf0 100644 --- a/aws_cloudfront_distribution.tf +++ b/aws_cloudfront_distribution.tf @@ -16,7 +16,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" { viewer_certificate { cloudfront_default_certificate = var.use_cloudfront_default_certificate - acm_certificate_arn = aws_acm_certificate.certificate.arn + acm_certificate_arn = var.use_cloudfront_default_certificate ? "" : aws_acm_certificate.certificate.arn ssl_support_method = "sni-only" minimum_protocol_version = var.minimum_protocol_version } @@ -28,9 +28,7 @@ resource "aws_cloudfront_distribution" "s3_distribution" { response_page_path = "/index.html" } - aliases = [ - var.distribution_fqdn - ] + aliases = var.use_cloudfront_default_certificate ? [] : [var.distribution_fqdn] logging_config { bucket = module.bucket_cloudwatch_logs_backup.s3_bucket_bucket_domain_name diff --git a/outputs.tf b/outputs.tf index 5779ef8..264bd8b 100644 --- a/outputs.tf +++ b/outputs.tf @@ -11,5 +11,5 @@ output "identity" { } output "domain_validations" { - value = aws_route53_record.certificate_validation + value = aws_acm_certificate.certificate.domain_validation_options }