- Lab
- A Cloud Guru
Using Terraform Dynamic Blocks and Built-in Functions to Deploy to AWS
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.
Path Info
Table of Contents
-
Challenge
Check Terraform Status
-
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.
-
-
Challenge
Clone Terraform Code and Switch to Proper Directory
- The Terraform code required for this lab has already been cloned onto the provided VM.
- Switch to the
section7-HoL-TF-DynBlocks-Funcs
directory where the code is located to perform the remaining tasks. - View the files in the directory.
-
Challenge
Examine the Code in the Files
- Closely examine the code in the
main.tf
file. - Review the contents of the
variables.tf
,script.sh
, andoutputs.tf
files.
- Closely examine the code in the
-
Challenge
Review and Deploy the Terraform Code
- Format the code using the
terraform fmt
command. - Initialize the working directory and download the required providers.
- Validate the code using the
terraform validate
command. - Review the actions that will be performed when you deploy the code using the
terraform plan
command. - Deploy the code with the
terraform apply --auto-approve
command.
- Format the code using the
-
Challenge
Test Out the Deployment and Clean Up
- View the outputs of the deployment within the CLI immediately upon successful execution.
- Verify that your resources were created as intended in the AWS Management Console.
- Verify that the webserver is up and running using the URL generated as an output.
- Tear down the infrastructure using the
terraform destroy --auto-approve
command.
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.