Files
devops-directive-terraform-…/06-organization-and-modules/web-app-module/dns.tf
2021-05-27 14:35:03 -07:00

27 lines
711 B
HCL

resource "aws_route53_zone" "primary" {
count = var.create_dns_zone ? 1 : 0
name = var.domain
}
data "aws_route53_zone" "primary" {
count = var.create_dns_zone ? 0 : 1
name = var.domain
}
locals {
dns_zone_id = var.create_dns_zone ? aws_route53_zone.primary[0].zone_id : data.aws_route53_zone.primary[0].zone_id
subdomain = var.environment_name == "production" ? "" : "${var.environment_name}."
}
resource "aws_route53_record" "root" {
zone_id = local.dns_zone_id
name = "${local.subdomain}${var.domain}"
type = "A"
alias {
name = aws_lb.load_balancer.dns_name
zone_id = aws_lb.load_balancer.zone_id
evaluate_target_health = true
}
}