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
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
- The Terraform code required for this lab has already been cloned onto the provided VM.
- Switch to the directory where the code is located to perform the remaining tasks.
- View the files in the directory.
- 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
- 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
- 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.