Using Terraform Dynamic Blocks and Built-in Functions to Deploy to AWS

1.25 hours
  • 5 Learning Objectives

About this Hands-on Lab

Terraform offers a strong set of features to help optimize your Terraform code. Two really useful features are dynamic blocks, which allow you to generate static repeated blocks within resources in Terraform; and built-in functions, which help you manipulate variables and data to suit your needs and help make your Terraform deployments better automated and more fault resilient.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Check Terraform Status
  1. Check that Terraform is installed and functioning properly using the terraform version command.

    Note: You do not need to worry about the version of Terraform being used in this lab.

Clone Terraform Code and Switch to Proper Directory
  1. The Terraform code required for this lab has already been cloned onto the provided VM.
  2. Switch to the directory where the code is located to perform the remaining tasks.
  3. View the files in the directory.
Examine the Code in the Files
  1. Closely examine the code in the main.tf file.
  2. Review the contents of the variables.tf, script.sh, and outputs.tf files.
Review and Deploy the Terraform Code
  1. Format the code using the terraform fmt command.
  2. Initialize the working directory and download the required providers.
  3. Validate the code using the terraform validate command.
  4. Review the actions that will be performed when you deploy the code using the terraform plan command.
  5. Deploy the code with the terraform apply --auto-approve command.
Test Out the Deployment and Clean Up
  1. View the outputs of the deployment within the CLI immediately upon successful execution.
  2. Verify that your resources were created as intended in the AWS Management Console.
  3. Verify that the webserver is up and running using the URL generated as an output.
  4. Tear down the infrastructure using the terraform destroy --auto-approve command.

Additional Resources

Link to the GitHub repository for this lab:

https://github.com/ACloudGuru-Resources/content-hashicorp-certified-terraform-associate-foundations.git

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?