Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update route 53 configuration to handle root and subdomain DNS records #77

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions terraform-modules/service/r53.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@ data "aws_route53_zone" "selected" {
private_zone = false
}

resource "aws_route53_record" "www" {
for_each = var.aws_managed_dns ? toset(var.host_names) : []
# Resource for root domain A record with alias
resource "aws_route53_record" "root" {
count = var.aws_managed_dns && length(regexall("[^.]*?.[^.]*?$", var.host_names[0])) > 0 ? 1 : 0

zone_id = data.aws_route53_zone.selected[0].zone_id
name = regexall("[^.]*?.[^.]*?$", var.host_names[0])[0]
type = "A"

alias {
name = var.alb_external_dns
zone_id = data.aws_route53_zone.selected[0].zone_id
evaluate_target_health = false
}
}

# Resource for subdomain CNAME records
resource "aws_route53_record" "subdomain" {
for_each = var.aws_managed_dns ? { for v in var.host_names : v => v if v != regexall("[^.]*?.[^.]*?$", var.host_names[0])[0] } : {}

zone_id = data.aws_route53_zone.selected[0].zone_id
name = each.value
Expand All @@ -21,5 +37,5 @@ variable "alb_external_dns" {

variable "aws_managed_dns" {
type = bool
description = "flag to either create record if domain is managed in AWS or output ALB DNS for user to manually create"
}
description = "Flag to either create record if domain is managed in AWS or output ALB DNS for user to manually create"
}
Loading