Manages a Route53 Hosted Zone. For managing Domain Name System Security Extensions (DNSSEC), see the aws_route53_key_signing_key
and aws_route53_hosted_zone_dnssec
resources.
resource "aws_route53_zone" "primary" {
name = "example.com"
}
For use in subdomains, note that you need to create a
aws_route53_record
of type NS
as well as the subdomain
zone.
resource "aws_route53_zone" "main" {
name = "example.com"
}
resource "aws_route53_zone" "dev" {
name = "dev.example.com"
tags = {
Environment = "dev"
}
}
resource "aws_route53_record" "dev-ns" {
zone_id = aws_route53_zone.main.zone_id
name = "dev.example.com"
type = "NS"
ttl = "30"
records = aws_route53_zone.dev.name_servers
}
resource "aws_route53_zone" "private" {
name = "example.com"
vpc {
vpc_id = aws_vpc.example.id
}
}
This resource supports the following arguments:
name
- (Required) This is the name of the hosted zone.comment
- (Optional) A comment for the hosted zone. Defaults to 'Managed by Terraform'.delegation_set_id
- (Optional) The ID of the reusable delegation set whose NS records you want to assign to the hosted zone. Conflicts with vpc
as delegation sets can only be used for public zones.force_destroy
- (Optional) Whether to destroy all records (possibly managed outside of Terraform) in the zone when destroying the zone.tags
- (Optional) A map of tags to assign to the zone. If configured with a provider default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.vpc
- (Optional) Configuration block(s) specifying VPC(s) to associate with a private hosted zone. Conflicts with the delegation_set_id
argument in this resource and any aws_route53_zone_association
resource specifying the same zone ID. Detailed below.vpc_id
- (Required) ID of the VPC to associate.vpc_region
- (Optional) Region of the VPC to associate. Defaults to AWS provider region.This resource exports the following attributes in addition to the arguments above:
arn
- The Amazon Resource Name (ARN) of the Hosted Zone.zone_id
- The Hosted Zone ID. This can be referenced by zone records.name_servers
- A list of name servers in associated (or default) delegation set.
Find more about delegation sets in AWS docs.primary_name_server
- The Route 53 name server that created the SOA record.tags_all
- A map of tags assigned to the resource, including those inherited from the provider default_tags
configuration block.In Terraform v1.5.0 and later, use an import
block to import Route53 Zones using the zone id
. For example:
import {
to = aws_route53_zone.myzone
id = "Z1D633PJN98FT9"
}
Using terraform import
, import Route53 Zones using the zone id
. For example:
% terraform import aws_route53_zone.myzone Z1D633PJN98FT9