Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon

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.

Google Cloud Platform icon

Path Info

Clock icon Intermediate
Clock icon 45m
Clock icon Mar 29, 2021

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Clone Terraform Code and Switch to the Proper Directory

    1. Clone the code required for the lab from the provided GitHub repository.
    2. Switch to the appropriate directory where the code required for this lab resides with cd content-hashicorp-certified-terraform-associate-foundations/section4-hol1.
  2. Challenge

    Use the 'fmt' Command to Format Any Unformatted Code Before Deployment

    1. Examine the code in the file.
    2. Format the code using the terraform fmt command.
    3. View the changes that were made to the code in the file.
    4. Initialize the Terraform working directory and fetch any required providers with the terraform init command.
    5. Deploy the code with the terraform apply command.
  3. Challenge

    Use the 'taint' Command to Replace a Resource

    1. Modify the provisioner in the file to change the webpage output for the aws_instance.webserver resource to Version 2.
    2. Taint the aws_instance.webserver resource using the terraform taint command.
    3. Deploy the code again to recreate and replace the tainted resource.
    4. Verify that the changes display on the webpage, validating that the resource was replaced.
  4. Challenge

    Use the 'import' Command to Import a Resource

    1. View the contents of the resource_ids.txt file to obtain the EC2 instance ID of the virtual machine you need to import.
    2. Create the associated aws_instance.webserver2 resource in the file.
    3. Import the resource to be managed by your Terraform configuration using the terraform import command.
    4. Verify that the resource was added and is now being tracked by the state file.
  5. Challenge

    Modify the Imported Resource

    1. Modify the imported aws_instance.webserver2 resource to customize its parameters.
    2. Deploy the code to implement the changes to the resource.
    3. Tear down the infrastructure using the terraform destroy command.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Start learning by doing today

View Plans