Advanced Terraform · Module 02
State and Teamwork
Understand what the state file holds and why it is sensitive, move it to a remote S3 backend with locking (on LocalStack), refactor addresses with moved and removed blocks instead of destroying, and split large states while sharing outputs safely.
What you will learn
- Read and inspect state: resources, attributes, serial and lineage, and the secrets it contains
- Configure an S3 backend with native locking, partial configuration and state migration
- Rename, move and forget resources with moved and removed blocks and terraform state commands
- Split a large configuration into several states and share values with outputs and data sources
Lessons
- Inside the State File
State maps every resource address in your code to a real object ID; it stores all attributes in plain text, including secrets, and is protected by serial and lineage.
- Remote Backends and State Locking
A backend stores state remotely; the S3 backend locks with a .tflock object (use_lockfile), takes environment-specific settings through partial configuration and migrates local state with init.
- Refactoring: moved, removed and state Commands
Rename or move resources without destroying them using moved blocks or terraform state mv, and stop managing something without deleting it using removed blocks or terraform state rm.
- Splitting State and Sharing Outputs
Split one big state into layers with a small blast radius, then pass values between them through outputs, terraform_remote_state or, better, data sources.