- Lab
- A Cloud Guru
Practicing Terraform CLI Commands (fmt, taint, and import)
In this hands-on lab, you'll be working with the Terraform fmt, taint, and import commands and understand what scenarios to use them in.
Path Info
Table of Contents
-
Challenge
Clone Terraform Code and Switch to the Proper Directory
- Clone the code required for the lab from the provided GitHub repository.
- Switch to the appropriate directory where the code required for this lab resides with
cd content-hashicorp-certified-terraform-associate-foundations/section4-hol1
.
-
Challenge
Use the 'fmt' Command to Format Any Unformatted Code Before Deployment
- Examine the code in the
main.tf
file. - Format the code using the
terraform fmt
command. - View the changes that were made to the code in the
main.tf
file. - Initialize the Terraform working directory and fetch any required providers with the
terraform init
command. - Deploy the code with the
terraform apply
command.
- Examine the code in the
-
Challenge
Use the 'taint' Command to Replace a Resource
- Modify the provisioner in the
main.tf
file to change the webpage output for theaws_instance.webserver
resource toVersion 2
. - Taint the
aws_instance.webserver
resource using theterraform taint
command. - Deploy the code again to recreate and replace the tainted resource.
- Verify that the changes display on the webpage, validating that the resource was replaced.
- Modify the provisioner in the
-
Challenge
Use the 'import' Command to Import a Resource
- View the contents of the
resource_ids.txt
file to obtain the EC2 instance ID of the virtual machine you need to import. - Create the associated
aws_instance.webserver2
resource in themain.tf
file. - Import the resource to be managed by your Terraform configuration using the
terraform import
command. - Verify that the resource was added and is now being tracked by the state file.
- View the contents of the
-
Challenge
Modify the Imported Resource
- Modify the imported
aws_instance.webserver2
resource to customize its parameters. - Deploy the code to implement the changes to the resource.
- Tear down the infrastructure using the
terraform destroy
command.
- Modify the imported
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.