Terraform Route53 Record Management in AWS

Route 53 is Amazon Web Services' highly flexible and available Domain Name System DNS web service. It gives developers and administrators the ability to manage domain names and route internet traffic to different AWS resources and different endpoints. Each DNS zone compares to a space name e.g., geeksforgeeks.com and contains records that characterize how area names are set out to IP addresses.

Terraform is an open-source infrastructure as-code instrument created by HashiCorp. It permits clients to characterize and arrange foundation resources using definitive setup records. Terraform automates the creation, modification, and deletion of resources across different cloud suppliers and on-premises conditions.

This article covers authoritative patterns for creating and managing AWS Route 53 records with Terraform, including the native aws_route53_record resource, community modules, routing policies, alias records, for_each patterns, import workflows, and validation record automation.

Core Resource Model

The aws_route53_record resource manages an Route53 Record resource.

A minimal configuration to get started is:

hcl resource "aws_route53_record" "example" { name = "my-route53-record" }

Refer to the Terraform Registry docs for all available arguments. A typical Route 53 record creation requires a zone reference and record attributes.

Provider configuration establishes the AWS connection used for all Route 53 operations:

hcl provider "aws" { region = "us-east-1" }

This section specifies the AWS provider and sets the region to "us-east-1". The provider block configures the authentication details and default settings for interacting with AWS.

AWS Route Creation defines an AWS Route 53 record resources named "example_record". It indicates the setup for a DNS record inside the Route 53 zone recently made. The characteristics of the record include:

  • zoneid: This characteristic references the ID of the Highway 53 zone where the record will be made. It utilizes the introduction sentence structure to get to the zone ID of the "examplezone" asset.
  • name: This indicates the domain name for the record. For this situation, it's example "www.geeksforgeeks.com".
  • type: This property characterizes the kind of DNS record

Key features of Route 53 include:

  • Domain Registration: Route 53 allows users to register and manage domain names directly through the service. By using Route 53 users can create their own domain name easily.
  • DNS Management: Users can create and manage DNS records, for example, A, AAAA, CNAME, MX, TXT, and so on. to map domain names to specific IP addresses or other DNS records.
  • Traffic Routing: Route 53 backings different routing arrangements, including simple routing, weighted routing, dormancy based routing, geolocation-based routing, and failover routing

Module Based Record Creation

A Terraform module creates a Route53 record in AWS. It provides a flexible way to configure various types of routing policies for your DNS records.

The module capabilities include:

  • Creates a Route53 record with the specified zone ID, name, type, TTL, and records.
  • Supports optional attributes
  • Supports different routing policies including geolocation, failover, latency, weighted, and CIDR-based routing.
  • Provides the option for alias records that can point to AWS resources using their AWS resource name.
  • Allows only one routing policy block to be supplied.
  • Adheres to security best practices by leveraging automated scanning with Checkov.

Examples are available and these examples use the latest version of this module.

A minimum example usage is:

hcl module "minimum_example" { source = "boldlink/route53-records/aws" version = "insert_latest_version" zone_id = local.zone_id name = var.name type = var.type ttl = var.ttl records = var.records }

Module requirements:

Name Version
terraform >= 0.14.11
aws >= 4.65.0

Provider pin:

Name Version
aws 5.23.1

No modules.

Resources created:

Name Type
awsroute53record.main resource

Input variables:

Name Description Type Default Required
alias (Optional) An alias block. Conflicts with ttl & records. any {} no
allow_overwrite Allow creation of this record in Terraform to overwrite an existing record, if any

Routing Policy Patterns

Route 53 supports multiple routing policies that can be expressed via Terraform modules and native resources.

The terraform-aws-modules/route53/aws module creates Route53 resources with a records map. An example zone definition is:

hcl module "zone" { source = "terraform-aws-modules/route53/aws" name = "terraform-aws-modules-example.com" comment = "Public zone for terraform-aws-modules example" records = { s3 = { name = "s3-bucket-z1bkctxd74ezpe.terraform-aws-modules-example.com" type = "A" alias = { name = "s3-website-eu-west-1.amazonaws.com" zone_id = "Z1BKCTXD74EZPE" } } mail = { full_name = "terraform-aws-modules-example.com" type = "MX" ttl = 3600 records = [ "1 aspmx.l.google.com", "5 alt1.aspmx.l.google.com", "5 alt2.aspmx.l.google.com", "10 alt3.aspmx.l.google.com", "10 alt4.aspmx.l.google.com", ] } geo = { type = "CNAME" ttl = 5 records = ["europe.test.example.com."] set_identifier = "europe" geolocation_routing_policy = { continent = "EU" } } geoproximity-aws-region = { type = "CNAME" ttl = 5 records = ["us-east-1.test.example.com."] set_identifier = "us-east-1-region" geoproximity_routing_policy = { aws_region = "us-east-1" bias = 0 } } geoproximity-coordinates = { type = "CNAME" ttl = 5 records = ["nyc.test.example.com."] set_identifier = "nyc" geoproximity_routing_policy = { coordinates = [{ latitude = "40.71" longitude = "-74.01" }] } } cloudfront_ipv4 = { name = "cloudfront" type = "A" alias = { name = "d3778kt32cqdww.cloudfront.net" zone_id = "EF3T6981F7M1" } } cloudfront_ipv6 = { name = "cloudfront" type = "AAAA" alias = { name = "d3778kt32cqdww.cloudfront.net" zone_id = "EF3T6981F7M1" } } } }

Alias records allow pointing to AWS resources using their AWS resource name. Alias blocks conflict with ttl and records.

Geolocation routing, geoproximity routing with AWS region bias or coordinates, weighted routing, failover, latency based routing and CIDR based routing are supported through the routing policy blocks. Only one routing policy block can be supplied per record.

For Each and Validation Automation

Managing Records with for_each keeps configurations DRY for multiple similar records.

```hcl
variable "subdomains" {
default = {
"api" = "10.0.1.10"
"admin" = "10.0.1.11"
"staging" = "10.0.2.10"
}
}

resource "awsroute53record" "subdomains" {
foreach = var.subdomains
zone
id = awsroute53zone.primary.zone_id
name = "${each.key}.example.com"
type = "A"
ttl = 300
records = [each.value]
}
```

For ACM certificate validation, a dynamic for_each over domain validation options is common:

```hcl
resource "awsroute53record" "certvalidation" {
for
each = {
for dvo in awsacmcertificate.main.domainvalidationoptions : dvo.domainname => {
name = dvo.resource
recordname
record = dvo.resource
recordvalue
type = dvo.resource
recordtype
}
}
allow
overwrite = true
name = each.value.name
records = [each.value.record]
ttl = 60
type = each.value.type
zoneid = awsroute53zone.primary.zoneid
}

resource "awsacmcertificatevalidation" "main" {
certificate
arn = awsacmcertificate.main.arn
validationrecordfqdns = [for record in awsroute53record.cert_validation : record.fqdn]
}
```

Wait for validation to complete after creating the records.

Importing Existing Records

If you have existing Route 53 records and want to bring them under Terraform management:

bash terraform import 'aws_route53_record.web' Z1234567890_example.com_A

Import a weighted record:

bash terraform import 'aws_route53_record.primary' Z1234567890_app.example.com_A_primary

The import ID format is {zoneid}{name}{type}, with {setidentifier} appended for routing-policy records.

Import IDs:
- Standard: Z1234567890example.comA
- Weighted: Z1234567890app.example.comA_primary

Installation Prerequisites

Step 2: Install Terraform

Now install terraform packages by using following below commands

bash sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo

Now install terraform by using following commands

bash sudo yum -y install terraform

Step 3: Create A File And Write Terraform Script for AWS Route 53 Using Terraform

Create a file with .tf extension in that file write a script by using following command

Best Practices

Use variables for zone IDs - Don't hardcode zone IDs

Additional operational guidance includes:

  • Use allow_overwrite = true when records may be recreated during validation workflows.
  • Keep TTL values low for records that require rapid propagation during testing, e.g., ttl = 5 for geo records and ttl = 60 for validation records.
  • Use alias records for AWS resources instead of CNAMEs to S3, CloudFront, ELB, and API Gateway endpoints.
  • Separate records by set_identifier for routing policy records to avoid conflicts.
  • Pin module versions and provider versions to ensure reproducible plans.

Conclusion

Terraform Route53 record management combines declarative DNS definitions with AWS routing intelligence. The native awsroute53record resource provides granular control over name, type, ttl, records, zoneid, allowoverwrite, and routing policy attributes. Community modules abstract repetition and support alias records, geolocation, geoproximity, failover, latency, weighted, and CIDR based routing in a single records map.

Foreach patterns scale subdomain and certificate validation workloads without duplication. Import workflows allow existing zones to be adopted with the {zoneid}{name}{type} identifier format, extended with set_identifier for policy records. Installation via yum repositories on Amazon Linux and provider configuration with region us-east-1 establishes the baseline for automation.

Together these techniques enable secure, repeatable, and policy rich DNS management that aligns Terraform state with Route 53's flexible routing model.

Sources

  1. https://github.com/TerraformFoundation/terraform-aws-route53-records
  2. https://awsfundamentals.com/terraform/route53/route53-record
  3. https://www.geeksforgeeks.org/devops/how-to-create-aws-route-53-using-terraform/
  4. https://github.com/terraform-aws-modules/terraform-aws-route53
  5. https://oneuptime.com/blog/post/2026-02-12-route-53-dns-terraform/view

Related Posts