Intermediate

State Management and Remote Backends

Migrate Terraform state from a local file to a remote S3 backend with DynamoDB state locking, then explore state manipulation commands for the situations where you need to intervene directly.

~2.5h
0 / 8 steps
🚀
Intro

What you're building

Terraform's state file is the map between your configuration and the real resources it manages — without it, Terraform has no way to know that the aws_instance.web block in your .tf file corresponds to a specific already-running EC2 instance rather than a new one to create. A local state file works fine solo, but breaks down the moment a second person needs to run Terraform against the same infrastructure: two people applying from two local state files is a fast path to conflicting, corrupted infrastructure state.

You'll migrate state to an S3 backend, add DynamoDB-based state locking so two concurrent applies can't corrupt the state, and learn the state subcommands (state mv, state rm, import) that let you intervene directly when reality and Terraform's tracked state disagree.

🔨

Step 1 — Provision the backend infrastructure

🔨

Step 2 — Configure the S3 backend and migrate state

🔨

Step 3 — Verify locking works

🔨

Step 4 — Inspect and manipulate state directly

🔨

Step 5 — Import an existing, unmanaged resource

🎯
Secret Mission

Secret Mission: simulate and recover from state corruption

🧹
Wrap Up

Before You Go

Pro

Test what you just learned

Self-testing is one of the best ways to retain new skills. Unlock project quizzes to check your understanding.

Log in to unlock