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
Labs

Using Terraform CLI Commands (workspace and state) to Manipulate a Terraform Deployment

In this hands-on lab, we will create two distinct, parallel environments against the same Terraform code using the `terraform workspace` command. We will also use the `terraform state` command to see what resources are being tracked in the state files of the different workspaces.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Advanced
Duration
Clock icon 1h 30m
Published
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.
    3. List the files in the directory.
  2. Challenge

    Create a New Workspace

    1. Check that no workspace other than the default one exists using the terraform workspace list command.
    2. Create a new workspace named test using the terraform workspace new command.
  3. Challenge

    Deploy Infrastructure in the Test Workspace and Confirm Deployment via the AWS Management Console

    1. In the test workspace, initialize the working directory and download the required providers.
    2. Examine the code in the main.tf and network.tf files to become familiar with the resources that will be created upon deployment.
    3. Deploy the code with the terraform apply --auto-approve command.
    4. Confirm that Terraform is tracking resources via a state file in the test workspace.
    5. Confirm that Terraform is not tracking resources via a state file in the default workspace.
    6. Verify that the resources were created as intended in the test workspace via the AWS Management Console.
  4. Challenge

    Deploy Infrastructure in the Default Workspace and Confirm Deployment via AWS Management Console

    1. Deploy the code in the default workspace with the terraform apply --auto-approve command.
    2. Confirm that Terraform is now tracking resources via a state file in the default workspace.
    3. Verify that the resources were created as intended in the default workspace via the AWS Management Console.
  5. Challenge

    Destroy Resources in the Workspaces and Delete the Test Workspace

    1. In the test workspace, tear down the infrastructure using the terraform destroy --auto-approve command.
    2. Verify that the resources were destroyed via the AWS Management Console.
    3. In the default workspace, delete the test workspace you created using the terraform workspace delete command.
    4. In the default workspace, tear down the infrastructure using the terraform destroy --auto-approve 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