Skip to content
EgyKode
11 · Operating itLab 57 / 59
Guided labterraformDestructive

Terraform Drift & State Recovery

Someone changed AWS by hand and someone else deleted the state. Recover from both without rebuilding anything.

Time
55 min
Level
Advanced
Objectives
4 objectives
Cost
Low cost

Where this fits in the platform

This lab adds

  • State recovered after the failure everyone hopes to avoid

Which lets you

Before you start

You will need

  • Terraform >= 1.6
  • AWS CLI v2, configured

You do not need these already — the lab environment below provides them.

You will be able to

  • Detect drift and decide whether to adopt or revert it
  • Import an existing resource into state
  • Recover a state file from a versioned backend

CostLow cost

— the exercises use an S3 bucket and a `t3.micro`. Nothing here bills hourly beyond the instance.

Nothing to pay in the browser. Open the terminal runs this against a simulated cloud — the same API calls and the same commands, with no account and no bill. The figure above applies only if you build it in your own.

How to clean up

The scenario#

Someone widened a security group in the console during an incident. Someone else ran terraform apply a week later and closed it again, causing a second incident.

Then the state file was deleted.

All three are recoverable. None of them require rebuilding the infrastructure — which is what people do when they do not know these commands.

This lab deletes state and modifies resources on purpose. Use a scratch configuration, never a real environment.

Hands-on environment

Run this lab in a real terminal, free and in your browser. The environment is temporary and yours alone — break it as much as you like.

Open the terminal

Opens in Killercoda, in a new tab — keep this page open for the steps.

Run it on AWS

This lab builds real cloud infrastructure, so it needs your own AWS account. Follow the cost and cleanup notes above — the resources are yours, and so is the bill.

Anything you tick here is your own record. EgyKode cannot see inside that terminal, so the success criteria stay self-assessed even when the environment checks your work for you.

Drift, detected

Step 1 of 5

Clean up#

Run this even if you did not finish.

DestructiveThis removes real resources. Check which environment you are in first.

Terminal
terraform destroy -auto-approve
aws s3 ls | grep tfstate-recovery

Cost of this lab: Free tier — the exercises use an S3 bucket and a t3.micro. Nothing here bills hourly beyond the instance.

Success criteria

0 of 4

The concept behind it

Ready to try it without help?Do the challenge

Next up

Lab 57 of 59 on the project path

Node Drain, Upgrade & RecoveryTake a node out of service without taking the application with it, and find out which workloads were never ready for it.55 minAdvanced

Previous: Chaos: Failure Injection & Recovery