All hands-on labs

Premium Hands-on labbeginnerAWS

Managing Terraform State and Drift

Terraform tracks everything it deploys in a state file, and any change made outside Terraform puts that file out of sync with reality. In this lab, you'll deploy an EC2 instance in a custom VPC, inspect and reshape its state with terraform state list, show, mv and rm, then create drift on purpose and decide how to resolve it.

  • 11 guided tasks
  • Terminal in the browser

Scenario

This lab is part of the Terraform on AWS course. It is the Managing Terraform state and drift lesson, and it continues from the Writing better Terraform lesson, where you split your code into the provider.tf, variables.tf, main.tf, and output.tf files. This lab uses the same four files, but for a new set of resources, so you'll start in a new directory. If you feel you are missing context, we recommend going through the course material.

Terraform records everything it deploys in a state file, and a change made outside Terraform creates drift between that file and AWS. In this lab, you'll deploy an EC2 instance in a custom VPC with Terraform and use the terraform state commands to inspect, rename, and remove resources in the state. Then you'll create drift on purpose, find it with terraform plan, resolve it, and tear everything down.

What you will learn

  • Deploy an EC2 instance in a custom VPC with Terraform.
  • Read the Terraform state file and list and show the resources in it.
  • Rename a resource with terraform state mv and remove one with terraform state rm.
  • Create drift outside Terraform, find it with terraform plan, and resolve it.
Hands-on lab

Managing Terraform State and Drift

Included in Cybr Premium.