Creating Route 53 Records (Alias) to Route Traffic to an ALB Using Terraform

45 minutes
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, the student will be creating a Route 53 alias record to route traffic from a publicly hosted zone in Route 53 (already provided by A Cloud Guru lab environment) to an application load balancer using Terraform template(s). Please note that changes to Route 53 records may take some time to propagate.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Log into the Terraform Controller node EC2 instance
  1. Find the details for logging in to the Terraform Controller node provided by the hands-on lab interface and log in to the node using SSH:

    ssh cloud_user@<IP-OF-TERRAFORM-CONTROLLER>

    Note: This instance already has an EC2 instance profile (role) attached to it and has all necessary AWS API permissions required for this lab. It also has the AWS CLI set up and configured with the AWS account attached to this lab, for which the console login credentials are also provided in the lab interface page once the lab spins up.

  2. After logging in, verify the version of Terraform installed (should be 12.29). Execute the following command to check:

    terraform version
Clone the GitHub repo for Terraform code

Use the git command to clone the GitHub repo which has the Terraform code for deploying the solution of this lab. GitHub repo URL.

  1. Execute the following command:

    git clone https://github.com/linuxacademy/content-deploying-to-aws-ansible-terraform.git
  2. Change to the directory for lab Terraform code:

    cd content-deploying-to-aws-ansible-terraform/lab_deploying_dns_acm
  3. Examine the contents of the directory you’re in:

    ls
Plug in the Provided Resource Values into `import_resources.tf`

You will need the values for a few pre-configured resources to complete this lab, such as Security Group IDs. These values can be found in the resource_id.txt file in the cloud_user home directory.

Absolute path to the resource_ids.txt file:

/home/cloud_user/resource_ids.txt

Complete path to file:

/home/cloud_user/resource_id.txt

Plug the appropriate value inside the import_resources.tf file inside the cloned Git repo folder:

content-deploying-to-aws-ansible-terraform/lab_deploying_dns_acm
Get Public Hosted Route53 Zone and plug it into variables.tf

A publicly-hosted domain is provided for you as part of this lab and your Terraform controller node has the permissions to make API calls to Route 53 to fetch it.

Carry out the following steps to fetch the domain and plug it into a variable:

  1. Issue the command:

    aws route53 list-hosted-zones | jq -r .HostedZones[].Name | egrep "cmcloud*"

    This will output a DNS name, ending with a dot.

  2. Copy the DNS value, ensure that you copy the trailing . at the end as well, and replace it against the default value of the dns-name variable in the variables.tf file.

Deploy the Terraform Code
  1. Initialize the Terraform directory you changed into to download the required provider

    terraform init
  2. Ensure Terraform code is formatted properly:

    terraform fmt
  3. Ensure code has proper syntax and no errors:

    terraform validate
  4. See the execution plan and note the number of resources that will be created:

    terraform plan
  5. Deploy resources:

    terraform apply

    Enter yes when prompted.

    After terraform apply has run successfully, you can either use the AWS CLI on the Controller node to list and describe created resources or you can log in to the AWS Console to verify and investigate created resources.

  6. Finally, on the Terraform Controller node CLI, delete all resources which were created and ensure that it runs through successfully.

    terraform destroy

Additional Resources

You're a consultant who's been called in to support a Terraform deployment project. The company enlisting your services has already deployed resources in AWS such as EC2 instances, security groups, subnet IDs, etc. They now require you to import those resources into a Terraform deployment and put it all behind a hosted zone in AWS Route 53.

The customer team has provided you AWS resource IDs for already existing resources in the file of the Terraform Controller node that you'll be logging in to:

/home/cloud_user/resource_ids.txt

You've been told that the publicly-hosted zone domain starts with the following letters: cmcloud.

You've already written down the code for the deployment and pushed it to this GitHub repo in the folder content-deploying-to-aws-ansible-terraform/lab_deploying_dns_acm:

https://github.com/linuxacademy/content-deploying-to-aws-ansible-terraform.git

All that needs to be done now is to get the resource IDs from the resource_ids file provided to you (mentioned above) by the customer team, plug the appropriate values inside the import_resources.tf file that you created for the integration, and deploy the Terraform code.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?