Resource: awsRoute53Record
Provides a Route53 record resource.
Example Usage
Simple routing policy
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.route53Record.Route53Record(this, "www", {
name: "www.example.com",
records: ["${aws_eip.lb.public_ip}"],
ttl: 300,
type: "A",
zoneId: "${aws_route53_zone.primary.zone_id}",
});
Weighted routing policy
Other routing policies are configured similarly. See Amazon Route 53 Developer Guide for details.
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.route53Record.Route53Record(this, "www-dev", {
name: "www",
records: ["dev.example.com"],
setIdentifier: "dev",
ttl: 5,
type: "CNAME",
weightedRoutingPolicy: {
weight: 10,
},
zoneId: "${aws_route53_zone.primary.zone_id}",
});
new aws.route53Record.Route53Record(this, "www-live", {
name: "www",
records: ["live.example.com"],
setIdentifier: "live",
ttl: 5,
type: "CNAME",
weightedRoutingPolicy: {
weight: 90,
},
zoneId: "${aws_route53_zone.primary.zone_id}",
});
Alias record
See related part of Amazon Route 53 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.
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsElbMain = new aws.elb.Elb(this, "main", {
availabilityZones: ["us-east-1c"],
listener: [
{
instancePort: 80,
instanceProtocol: "http",
lbPort: 80,
lbProtocol: "http",
},
],
name: "foobar-terraform-elb",
});
new aws.route53Record.Route53Record(this, "www", {
alias: {
evaluateTargetHealth: true,
name: awsElbMain.dnsName,
zoneId: awsElbMain.zoneId,
},
name: "example.com",
type: "A",
zoneId: "${aws_route53_zone.primary.zone_id}",
});
NS and SOA Record Management
When creating Route 53 zones, the ns
and soa
records for the zone are automatically created. Enabling the allowOverwrite
argument will allow managing these records in a single Terraform run without the requirement for terraformImport
.
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsRoute53ZoneExample = new aws.route53Zone.Route53Zone(this, "example", {
name: "test.example.com",
});
const awsRoute53RecordExample = new aws.route53Record.Route53Record(
this,
"example_1",
{
allowOverwrite: true,
name: "test.example.com",
records: [
`\${${awsRoute53ZoneExample.nameServers.fqn}[0]}`,
`\${${awsRoute53ZoneExample.nameServers.fqn}[1]}`,
`\${${awsRoute53ZoneExample.nameServers.fqn}[2]}`,
`\${${awsRoute53ZoneExample.nameServers.fqn}[3]}`,
],
ttl: 172800,
type: "NS",
zoneId: awsRoute53ZoneExample.zoneId,
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsRoute53RecordExample.overrideLogicalId("example");
Argument Reference
The following arguments are supported:
zoneId
- (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 area
,aaaa
,caa
,cname
,ds
,mx
,naptr
,ns
,ptr
,soa
,spf
,srv
andtxt
.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"
).setIdentifier
- (Optional) Unique identifier to differentiate records with routing policies from one another. Required if usingcidrRoutingPolicy
,failoverRoutingPolicy
,geolocationRoutingPolicy
,latencyRoutingPolicy
,multivalueAnswerRoutingPolicy
, orweightedRoutingPolicy
.healthCheckId
- (Optional) The health check the record should be associated with.alias
- (Optional) An alias block. Conflicts withttl
&records
. Documented below.cidrRoutingPolicy
- (Optional) A block indicating a routing policy based on the IP network ranges of requestors. Conflicts with any other routing policy. Documented below.failoverRoutingPolicy
- (Optional) A block indicating the routing behavior when associated health check fails. Conflicts with any other routing policy. Documented below.geolocationRoutingPolicy
- (Optional) A block indicating a routing policy based on the geolocation of the requestor. Conflicts with any other routing policy. Documented below.latencyRoutingPolicy
- (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.multivalueAnswerRoutingPolicy
- (Optional) Set totrue
to indicate a multivalue answer routing policy. Conflicts with any other routing policy.weightedRoutingPolicy
- (Optional) A block indicating a weighted routing policy. Conflicts with any other routing policy. Documented below.allowOverwrite
- (Optional) Allow creation of this record in Terraform to overwrite an existing record, if any. This does not affect the ability to update the record in Terraform and does not prevent other resources within Terraform or manual Route 53 changes outside Terraform from overwriting this record.false
by default. This configuration is not recommended for most environments.
Exactly one of records
or alias
must be specified: this determines whether it's an alias record.
Alias
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.zoneId
- (Required) Hosted zone ID for a CloudFront distribution, S3 bucket, ELB, or Route 53 hosted zone. SeeresourceElbZoneId
for example.evaluateTargetHealth
- (Required) Set totrue
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.
CIDR Routing Policy
CIDR routing policies support the following:
collectionId
- (Required) The CIDR collection ID. See theawsRoute53CidrCollection
resource for more details.locationName
- (Required) The CIDR collection location name. See theawsRoute53CidrLocation
resource for more details. AlocationName
with an asterisk"*"
can be used to create a default CIDR record.collectionId
is still required for default record.
Failover Routing Policy
Failover routing policies support the following:
type
- (Required)primary
orsecondary
. Aprimary
record will be served if its healthcheck is passing, otherwise thesecondary
will be served. See http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/dns-failover-configuring-options.html#dns-failover-failover-rrsets
Geolocation Routing Policy
Geolocation routing policies support the following:
continent
- A two-letter continent code. See http://docs.aws.amazon.com/Route53/latest/APIReference/API_GetGeoLocation.html for code details. Eithercontinent
orcountry
must be specified.country
- A two-character country code or*
to indicate a default resource record set.subdivision
- (Optional) A subdivision code for a country.
Latency Routing Policy
Latency routing policies support the following:
region
- (Required) An AWS region from which to measure latency. See http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-latency
Weighted Routing Policy
Weighted routing policies support the following:
weight
- (Required) A numeric value indicating the relative weight of the record. See http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-weighted.
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 andname
.
Import
Route53 Records can be imported using ID of the record, which is the zone identifier, record name, and record type, separated by underscores (_
)E.g.,
If the record also contains a set identifier, it should be appended: