Module 4: The Archive
Terraform has a "Memory." Even if you delete your code, Terraform still remembers what it built in the cloud. This memory is stored in a file called terraform.tfstate.
Tactical Intel: The State File
This is the most sensitive file in a Terraform project. It contains a map of your code to the real-world resources.
- Rule #1: Never edit this file by hand.
- Rule #2: Never delete this file while resources are still running (or Terraform will "forget" they exist).
Step 1: The Inspection
Once you've run apply, Terraform creates the .tfstate file in your directory.
Mission: Verify the archive exists.
Run: ls terraform.tfstate
Step 2: Querying the Memory
Instead of reading the messy JSON inside the state file, we use the terraform state command to ask Terraform what it remembers.
Mission: Ask Terraform to list all the resources it is currently tracking.
Run: terraform state list
Tactical Insight: State Locking
In a real team, multiple people might try to run Terraform at the same time. To prevent them from corrupting the "Memory," Terraform use State Locking. Only one person can edit the world at a time!