Skip to content

Commit

Permalink
feat(multiple domains): Add possibility to ACM for multiple zones and…
Browse files Browse the repository at this point in the history
… create DNS record in extra zones
  • Loading branch information
joli-sys committed Oct 14, 2024
1 parent 2620855 commit 1471eb9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
24 changes: 20 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ module "certificate" {
}

source = "terraform-aws-modules/acm/aws"
version = "5.0.0"
version = "5.1.1"

domain_name = local.main_domain
zone_id = var.domain_zone_id

subject_alternative_names = local.alternative_domains
subject_alternative_names = merge(local.alternative_domains, keys(extra_domains))

validation_method = "DNS"
wait_for_validation = true

zones = var.extra_domains

tags = local.tags
}

Expand Down Expand Up @@ -338,8 +340,22 @@ resource "aws_cloudfront_distribution" "this" {
resource "aws_route53_record" "this" {
for_each = toset(var.domains)

zone_id = var.domain_zone_id
name = each.value
zone_id = each.value
name = each.key
type = "A"

alias {
name = aws_cloudfront_distribution.this.domain_name
zone_id = aws_cloudfront_distribution.this.hosted_zone_id
evaluate_target_health = false
}
}

resource "aws_route53_record" "extra" {
for_each = var.extra_domains

zone_id = each.value
name = each.key
type = "A"

alias {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,9 @@ variable "response_header_access_control_allow_credentials" {
type = bool
default = false
}

variable "extra_domains" {
type = map(string)
description = "Map of extra_domains with domain name and zone_id"
default = {}
}

0 comments on commit 1471eb9

Please sign in to comment.