Route53

Usually traffic is routed via domain names and not IP addresses. Route53 provides the means of DNS zones in AWS. In this example I will create a DNS zone using Route53 and then add three DNS recordss in there.

Let's start by creating a file with the name vars.tf,

variable "AWS_REGION" {
  default = "eu-west-1"
}

Then a file with the name provider.tf,

provider "aws" {
  region = var.AWS_REGION
}

Finally our route53.tf file,

resource "aws_route53_zone" "isurusiri-com" {
  name = "isurusiri.com"
}

resource "aws_route53_record" "server1-record" {
  zone_id = aws_route53_zone.isurusiri-com.zone_id
  name    = "server.isurusiri.com"
  type    = "A"
  ttl     = "300"
  records = ["103.137.247.5"]
}

resource "aws_route53_record" "www-record" {
  zone_id = aws_route53_zone.isurusiri-com.zone_id
  name    = "www.isurusiri.com"
  type    = "A"
  ttl     = "300"
  records = ["103.137.247.5"]
}

resource "aws_route53_record" "mail1-record" {
  zone_id = aws_route53_zone.isurusiri-com.zone_id
  name    = "isurusiri.com"
  type    = "MX"
  ttl     = "300"
  records = [
    "1 aspmx.l.google.com.",
    "5 alt1.aspmx.l.google.com.",
    "5 alt2.aspmx.l.google.com.",
    "10 aspmx2.googlemail.com.",
    "10 aspmx3.googlemail.com.",
  ]
}

output "ns-servers" {
  value = aws_route53_zone.isurusiri-com.name_servers
}

In here, I first declare a Route53 DNS zone. Then I define 3 DNS records. First two are for the domain names pointing to a server with IP address 103.137.247.5. Then the final record is for the email configurations with G-Suite.

Initialize the providers,

$ terraform init

Apply the changes,

$ terraform apply

Don't forget to clean up once experiments are done,

$ terraform destroy

Last updated