- 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.
- List the files in the directory.
-
Challenge
Create a New Workspace
- Check that no workspace other than the
defaultone exists using theterraform workspace listcommand. - Create a new workspace named
testusing theterraform workspace newcommand.
- Check that no workspace other than the
-
Challenge
Deploy Infrastructure in the Test Workspace and Confirm Deployment via the AWS Management Console
- In the
testworkspace, initialize the working directory and download the required providers. - Examine the code in the
main.tfandnetwork.tffiles to become familiar with the resources that will be created upon deployment. - Deploy the code with the
terraform apply --auto-approvecommand. - Confirm that Terraform is tracking resources via a state file in the
testworkspace. - Confirm that Terraform is not tracking resources via a state file in the
defaultworkspace. - Verify that the resources were created as intended in the
testworkspace 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
defaultworkspace with theterraform apply --auto-approvecommand. - Confirm that Terraform is now tracking resources via a state file in the
defaultworkspace. - Verify that the resources were created as intended in the
defaultworkspace via the AWS Management Console.
- Deploy the code in the
-
Challenge
Destroy Resources in the Workspaces and Delete the Test Workspace
- In the
testworkspace, tear down the infrastructure using theterraform destroy --auto-approvecommand. - Verify that the resources were destroyed via the AWS Management Console.
- In the
defaultworkspace, delete thetestworkspace you created using theterraform workspace deletecommand. - In the
defaultworkspace, tear down the infrastructure using theterraform destroy --auto-approvecommand.
- 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.
