The route53.tf File¶
| Filename | Location | Group | Project/Repository |
|---|---|---|---|
route53.tf | ./route53.tf | infrastructure | terraform |
Why?¶
Without DNS records users will have to access our application via the AWS ALB's DNS hostname or its IP (which might change.) This isn't ideal as neither option is very easy to remember or use.
Instead we'll create some DNS records inside of an existing Route53 Zone so that we can redirect traffic to the correct AWS ALB, making it easier for our users to use our application.
Breakdown¶
Because we're using a pre-existing Route53 Zone the first thing we need to do is fetch the ID of it. This is the first time we're using a data {} block in our code:
1 2 3 | |
Using the name attribute we're able to search for a particular DNS zone. We could find the zone ID manually in the AWS UI and hard code it, but this is a better option in the long term.
Now we create some DNS records against this zone ID:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
We create three records: one for our ALB, a two additional records that point directly at our EC2 Instance's EIPs.
The Solution¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Terraform Documentation¶
| Type | Documentation |
|---|---|
aws_route53_zone (data) | Terraform AWS Provider |
aws_route53_record | Terraform AWS Provider |
Committing the Code¶
- Set your working directory to the
infrastructure/terraformrepository - Save the file as
route53.tfand usegit add route53.tfto add it to the Git staging area - Use
git commit -am 'setting up DNS record for our application'to commit the file to our repository - Push the code to GitLab.com:
git push