Exploring Terraform State Functionality

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Understanding and being comfortable with Terraform state is crucial to mastering it. In this hands-on lab, we will deploy resources using Kubernetes, a container orchestration tool, and see how Terraform maintains a state file to track changes and deploy containers declaratively.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Check Terraform and Minikube Status
  1. Check that Terraform is installed and functioning properly using the terraform version command.
  2. Check that the Kubernetes backedn process minikube is running properly using the minikube status command.
Clone Terraform Code and Switch to the Proper Directory
  1. The Terraform code required for this lab has already been cloned onto the provided VM.
  2. Switch to the directory where the code is located to perform the remaining tasks:
  3. View the code in the main.tf file to see what has been configured for deployment.
Deploy Terraform Code And Observe the State File
  1. Initialize the working directory and download the required providers.
  2. Review the actions that will be performed when code is deployed using the terraform plan command.
  3. Deploy the code with the terraform apply command.
  4. List the files and verify that the state file was created.
  5. List all the resources being tracked by the Terraform state file using the terraform state command.
  6. View the replicas being tracked by the Terraform state file and note the number.
  7. Modify the replicas attribute in the Terraform code and deploy the code again.
  8. View the replicas being tracked by the Terraform state file and verify that the number has changed.
  9. Remove the infrastructure you created using the terraform destroy command. However, note that Terraform leaves behind a terraform.tfstate.backup file in case you need to recover to the last deployed Terraform state.

As you make your way through this objective, you may also choose to verify that the number of pods configured in the code were created and that this number changes as you modify the replicas attribute in your code using the kubectl command.

Additional Resources

Link to the GitHub respository containing Terraform code for this lab:


Note: Please give the lab an extra minute before connecting via ssh.

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?