Menu

Smart DNS: Auto-Detecting Route53 Records in Terraform
πŸ“°

Smart DNS: Auto-Detecting Route53 Records in Terraform

DEV CommunityΒ·BartΕ‚omiej DanekΒ·7 months ago
#xONEpHKo
#aws#dns#route53#terraform#name
Reading 0:00
15s threshold

Smart DNS: Auto-Detecting Route53 Records in Terraform

Every Route53 record in plain Terraform means a zone lookup, an explicit type, and for load balancers - a separate data source just to wire the alias.

data "aws_route53_zone" "this" { name = "api.example.com." }

data "aws_lb" "api" { name = "api-nlb" }

resource "aws_route53_record" "api" { zone_id = data . aws_route53_zone . this . zone_id name = "api.example.com" type = "A"

alias { name = data . aws_lb . api . dns_name zone_id = data . aws_lb . api . zone_id evaluate_target_health = true } }

Enter fullscreen mode

Exit fullscreen mode

With a module that infers everything, the same record becomes:

inputs = { name = "api.example.com" records = "api-nlb-1234567890.elb.eu-west-1.amazonaws.com" }

Enter fullscreen mode

Exit fullscreen mode

zone auto-detection

name = "api.example.com" β”‚ └─ strip first label β”‚ β–Ό "example.com" ──► aws_route53_zone lookup

Enter fullscreen mode

Exit fullscreen mode

The module splits the FQDN, drops the first label,…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.