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. Valid values are A, AAAA, CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SPF, SRV and TXT.
  • ttl - (Required for non-alias records) The TTL of the record.
  • records - (Required for non-alias records) A string list of records. To specify a single record value longer than 255 characters such as a TXT record for DKIM, add \"\" inside the Terraform configuration string (e.g. "first255characters\"\"morecharacters").
  • 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.
  • multivalue_answer_routing_policy - (Optional) Set to true to indicate a multivalue answer routing policy. Conflicts with any other routing policy.
  • allow_overwrite - (Optional) Allow creation of this record in Terraform to overwrite an existing record, if any. This does not prevent other resources within Terraform or manual Route53 changes from overwriting this record. true by default.

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

In addition to all arguments above, the following attributes are exported:

  • name - The name of the record.
  • fqdn - FQDN built using the zone domain and name.

Import

Route53 Records can be imported using ID of the record. The ID is made up as ZONEID_RECORDNAME_TYPE_SET-IDENTIFIER

e.g.

Z4KAPRWWNC7JR_dev.example.com_NS_dev

In this example, Z4KAPRWWNC7JR is the ZoneID, dev.example.com is the Record Name, NS is the Type and dev is the Set Identifier. Only the Set Identifier is actually optional in the ID

To import the ID above, it would look as follows:

$ terraform import aws_route53_record.myrecord Z4KAPRWWNC7JR_dev.example.com_NS_dev

© 2018 HashiCorp
Licensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/aws/r/route53_record.html