Adding Route 53 records using Terraform

Posted: February 5, 2018 in Amazon Web Services (AWS), AWS, Linux, terraform

Amazon Route 53 (Route 53) is a scalable and highly available Domain Name System (DNS). It is part of Amazon.com’s cloud computing platform, Amazon Web Services (AWS). The name is a reference to TCP or UDP port 53, where DNS server requests are addressed

route3.tf file

In this file DNS zone astrahome.xyz is created, added two A records, one for WWW and second for server1, then one MX record with TTL (time-to-live),determines how frequently your DNS records get updated.MX records are in fact google mail servers

104.236.247.8 presents public IP address

Last section just outputs Amazon name servers

resource "aws_route53_zone" "some-zone" {
name = "astrahome.xyz"
}
resource "aws_route53_record" "server1-record" {
zone_id = "${aws_route53_zone.some-zone.zone_id}"
name = "server1.astrahome.xyz"
type = "A"
ttl = "300"
records = ["104.236.247.8"]
}
resource "aws_route53_record" "www-record" {
zone_id = "${aws_route53_zone.some-zone.zone_id}"
name = "www.astrahome.xyz"
type = "A"
ttl = "300"
records = ["104.236.247.8"]
}
resource "aws_route53_record" "mail1-record" {
zone_id = "${aws_route53_zone.some-zone.zone_id}"
name = "aztrahome.xyz"
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.some-zone.name_servers}"
}

provider.tf-specifies AWS region

provider "aws" {
    region = "${var.AWS_REGION}"
}

vars.tf-variable file, in this case we defined only one variable-aws region

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

Unlike previous examples, in this one we don’t need file with AWS credentials, because we can install AWS CLI tools, but first we need to install python, because i’m used CentOS minimal, i used this approach to install it. Then i installed AWS CLI.

Now keys are located on local machine (ls ~/.aws), so no need for storing it on terraform file.When Route 53 is deployed using terraform

1.PNG

 

We can check AWS console

1.PNG

 

Advertisements
Comments
  1. wykydtronik says:

    Aside from the “www” a record, how would you write the A record for the domain? Usually specified as @ for where exampledomain.com goes too.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s