- Lab
- A Cloud Guru
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.
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:
cd content-hashicorp-certified-terraform-associate-foundations/section4-lesson3/
- List the files in the directory.
-
Challenge
Create a New Workspace
- Check that no workspace other than the
default
one exists using theterraform workspace list
command. - Create a new workspace named
test
using theterraform workspace new
command.
- Check that no workspace other than the
-
Challenge
Deploy Infrastructure in the Test Workspace and Confirm Deployment via the AWS Management Console
- In the
test
workspace, initialize the working directory and download the required providers. - Examine the code in the
main.tf
andnetwork.tf
files to become familiar with the resources that will be created upon deployment. - Deploy the code with the
terraform apply --auto-approve
command. - Confirm that Terraform is tracking resources via a state file in the
test
workspace. - Confirm that Terraform is not tracking resources via a state file in the
default
workspace. - Verify that the resources were created as intended in the
test
workspace via the AWS Management Console.
- In the
-
Challenge
Deploy Infrastructure in the Default Workspace and Confirm Deployment via AWS Management Console
- Deploy the code in the
default
workspace with theterraform apply --auto-approve
command. - Confirm that Terraform is now tracking resources via a state file in the
default
workspace. - Verify that the resources were created as intended in the
default
workspace via the AWS Management Console.
- Deploy the code in the
-
Challenge
Destroy Resources in the Workspaces and Delete the Test Workspace
- In the
test
workspace, tear down the infrastructure using theterraform destroy --auto-approve
command. - Verify that the resources were destroyed via the AWS Management Console.
- In the
default
workspace, delete thetest
workspace you created using theterraform workspace delete
command. - In the
default
workspace, tear down the infrastructure using theterraform destroy --auto-approve
command.
- In the
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.