- Lab
- A Cloud Guru
Exploring Terraform State Functionality
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.
Path Info
Table of Contents
-
Challenge
Check Terraform and Minikube Status
- Check that Terraform is installed and functioning properly using the
terraform version
command. - Check that the Kubernetes backedn process
minikube
is running properly using theminikube status
command.
- Check that Terraform is installed and functioning properly using the
-
Challenge
Clone Terraform Code and Switch to the Proper Directory
- The Terraform code required for this lab has already been cloned onto the provided VM.
- Switch to the directory where the code is located to perform the remaining tasks:
lab_code/section2-hol1
- View the code in the
main.tf
file to see what has been configured for deployment.
-
Challenge
Deploy Terraform Code And Observe the State File
- Initialize the working directory and download the required providers.
- Review the actions that will be performed when code is deployed using the
terraform plan
command. - Deploy the code with the
terraform apply
command. - List the files and verify that the state file was created.
- List all the resources being tracked by the Terraform state file using the
terraform state
command. - View the replicas being tracked by the Terraform state file and note the number.
- Modify the
replicas
attribute in the Terraform code and deploy the code again. - View the replicas being tracked by the Terraform state file and verify that the number has changed.
- Remove the infrastructure you created using the
terraform destroy
command. However, note that Terraform leaves behind aterraform.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 thekubectl
command.
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.