This Terraform module creates and manages an AWS Route53 hosted zone, along with DNS records. It supports both public and private hosted zones, and allows the creation of various DNS records.
- Create Hosted Zone: Optionally create a new Route53 hosted zone (public or private).
- NS and SOA Records: Automatically create NS and SOA records for the hosted zone.
- User-Defined Records: Dynamically create custom DNS records based on user input.
module "route53" {
source = "./path-to-module"
create_hosted_zone = true
zone_name = "example.com"
is_private_zone = false
vpc_id = "vpc-123456"
ns_record_ttl = 300
soa_record_ttl = 7200
enable_records = true
records = [
{
name = "www.example.com"
type = "A"
ttl = 300
records = ["192.0.2.44"]
},
{
name = "mail.example.com"
type = "MX"
ttl = 3600
records = ["10 mailserver.example.com"]
}
]
}
Name | Description | Type | Default | Required |
---|---|---|---|---|
create_hosted_zone | Whether to create a new Route53 hosted zone | bool |
false |
no |
zone_name | The name of the domain. Required if create_hosted_zone is true | string |
"" |
no |
is_private_zone | Whether the hosted zone is private | bool |
false |
no |
vpc_id | The VPC ID for private hosted zones. Required if is_private_zone is true | string |
"" |
no |
ns_record_ttl | The TTL for the NS record. Only used for public zones | number |
300 |
no |
soa_record_ttl | The TTL for the SOA record. Only used for public zones | number |
7200 |
no |
enable_records | Whether to create custom DNS records | bool |
false |
no |
records | A list of DNS records to create. Each record should include name, type, ttl, and records fields | list(object) |
[] |
no |
existing_zone_id | The ID of an existing Route53 hosted zone to use. Required if create_hosted_zone is false | string |
"" |
no |
module "route53" {
source = "./path-to-module"
create_hosted_zone = true
zone_name = "example.com"
is_private_zone = false
ns_record_ttl = 300
soa_record_ttl = 7200
enable_records = true
records = [
{
name = "www.example.com"
type = "A"
ttl = 300
records = ["192.0.2.44"]
}
]
}
module "route53" {
source = "./path-to-module"
create_hosted_zone = false
existing_zone_id = "Z1234567890"
enable_records = true
records = [
{
name = "www.example.com"
type = "A"
ttl = 300
records = ["192.0.2.44"]
}
]
}