aws_route53_record

Provides a Route53 record resource.

Example Usage

Simple routing policy

resource "aws_route53_record" "www" {
   zone_id = "${aws_route53_zone.primary.zone_id}"
   name = "www.example.com"
   type = "A"
   ttl = "300"
   records = ["${aws_eip.lb.public_ip}"]
}

Weighted routing policy

Other routing policies are configured similarly. See AWS Route53 Developer Guide for details.

resource "aws_route53_record" "www-dev" {
  zone_id = "${aws_route53_zone.primary.zone_id}"
  name = "www"
  type = "CNAME"
  ttl = "5"
  weighted_routing_policy {
    weight = 10
  }
  set_identifier = "dev"
  records = ["dev.example.com"]
}

resource "aws_route53_record" "www-live" {
  zone_id = "${aws_route53_zone.primary.zone_id}"
  name = "www"
  type = "CNAME"
  ttl = "5"
  weighted_routing_policy {
    weight = 90
  }
  set_identifier = "live"
  records = ["live.example.com"]
}

Alias record

See related part of AWS Route53 Developer Guide to understand differences between alias and non-alias records.

TTL for all alias records is 60 seconds, you cannot change this, therefore ttl has to be omitted in alias records.

resource "aws_elb" "main" {
  name = "foobar-terraform-elb"
  availability_zones = ["us-east-1c"]

  listener {
    instance_port = 80
    instance_protocol = "http"
    lb_port = 80
    lb_protocol = "http"
  }
}

resource "aws_route53_record" "www" {
  zone_id = "${aws_route53_zone.primary.zone_id}"
  name = "example.com"
  type = "A"

  alias {
    name = "${aws_elb.main.dns_name}"
    zone_id = "${aws_elb.main.zone_id}"
    evaluate_target_health = true
  }
}

Argument Reference

The following arguments are supported:

  • zone_id - (Required) The ID of the hosted zone to contain this record.
  • name - (Required) The name of the record.
  • type - (Required) The record type.
  • ttl - (Required for non-alias records) The TTL of the record.
  • records - (Required for non-alias records) A string list of records.
  • set_identifier - (Optional) Unique identifier to differentiate records with routing policies from one another. Required if using failover, geolocation, latency, or weighted routing policies documented below.
  • health_check_id - (Optional) The health check the record should be associated with.
  • alias - (Optional) An alias block. Conflicts with ttl & records. Alias record documented below.
  • failover_routing_policy - (Optional) A block indicating the routing behavior when associated health check fails. Conflicts with any other routing policy. Documented below.
  • geolocation_routing_policy - (Optional) A block indicating a routing policy based on the geolocation of the requestor. Conflicts with any other routing policy. Documented below.
  • latency_routing_policy - (Optional) A block indicating a routing policy based on the latency between the requestor and an AWS region. Conflicts with any other routing policy. Documented below.
  • weighted_routing_policy - (Optional) A block indicating a weighted routing policy. Conflicts with any other routing policy. Documented below.

Exactly one of records or alias must be specified: this determines whether it's an alias record.

Alias records support the following:

  • name - (Required) DNS domain name for a CloudFront distribution, S3 bucket, ELB, or another resource record set in this hosted zone.
  • zone_id - (Required) Hosted zone ID for a CloudFront distribution, S3 bucket, ELB, or Route 53 hosted zone. See resource_elb.zone_id for example.
  • evaluate_target_health - (Required) Set to true if you want Route 53 to determine whether to respond to DNS queries using this resource record set by checking the health of the resource record set. Some resources have special requirements, see related part of documentation.

Failover routing policies support the following:

Geolocation routing policies support the following:

Latency routing policies support the following:

Weighted routing policies support the following:

Attributes Reference

  • fqdn - FQDN built using the zone domain and name