Skip to content

DNS (Route 53)

Create Public DNS Zones

To create a public DNS zone define the dns_zones variable, and optionally define desired records for each zone. The @ character is used to represent the root domain.

dns_zones = {
    "testzone1.com" = {
        comment = "testzone1.com DNS Zone"
        records = [
            {
                name = "@"
                type = "A"
                records = ["34.224.10.110", "52.11.37.152"]
            },
            {
                name = "test"
                type = "A"
                records = ["8.8.8.8"]
            },
            {
                name = "multi.subdomain"
                type = "CNAME"
                ttl = 60
                records = ["testzone1.com"]
            }
        ]
    }
    "testzone2.com" = {
        comment = "testzone2.com DNS Zone"
        records = [
            {
                name = "www"
                type = "A"
                records = ["34.224.10.110", "52.11.37.152"]
            }
        ]
    }
}

Create Private DNS Zones

Private DNS zones Are created identically to public zones, but must contain one or more VPCs in the vpcs list attribute. If no VPCs are defined, the zone will be considered a public zone.

vpcs = {
    VPC1 = {
        cidr_block = "10.198.1.128/25"
    }
    VPC2 = {
        cidr_block = "10.199.1.128/25"
    }
}

dns_zones = {
    "private.testzone.com" = {
        vpcs = ["VPC1", "VPC2"]
        comment = "private.testzone.com DNS Zone"
        records = [
            {
                name = "@"
                type = "A"
                ttl = 300
                records = ["34.224.10.110", "52.11.37.152"]
            }
        ]
    }
}

Create Records within an Existing Zone

To create DNS records within an existing zone, define the zone ID for an existing zone using the id attribute in the dns_zones variable.

dns_zones = {
    "testzone.com" = {
        id = "Z07529581V1QA9VLL0IX0"
        records = [
            {
                name = "@"
                type = "A"
                ttl = 300
                records = ["34.224.10.110", "52.11.37.152"]
            },
            {
                name = "multi.subdomain"
                type = "CNAME"
                ttl = 60
                records = ["testzone.com"]
            }
        ]
    }
}