Terraform Remote State in S3
Part of the AWS Roadmap
In short
Terraform's state file is its memory of what it built. Keep it on one laptop, or let two people apply at once, and you get duplicated servers or a corrupted file.
Terraform's state file records what it has built. For team use it is stored remotely, commonly in an S3 bucket with versioning and encryption, with state locking so two people cannot apply at the same time.

Think of it like this
The society maintenance ledger
A housing society keeps one ledger of who paid what. It stays locked in the office, and only one person writes in it at a time. If two treasurers kept separate notebooks, the accounts would never match. Remote state with locking is that one ledger.
Watch it happen
Two engineers, one locked state
lock + read state
1/5Riya runs apply. Terraform first takes a lock on the state, then reads it.
The big ideas
What you need to know
State maps code to reality
It links each resource block to a real cloud ID. Without it, Terraform can't tell what it already made.
Remote backend
Store state in a shared, versioned backend like an S3 bucket, GCS bucket or Terraform Cloud, never only on a laptop.
Locking
Locking stops two applies at once. The S3 backend can lock using a lock file in the bucket itself.
State holds secrets
State can contain passwords and keys in plain text. Encrypt it, restrict access and never commit it to Git.
See it in code
Walk through the code
1terraform {2 backend "s3" {3 bucket = "shop-tf-state"4 key = "prod/network.tfstate"5 region = "ap-south-1"6 encrypt = true7 use_lockfile = true # S3-native locking (Terraform 1.10+)8 }9}1/3State lives in one bucket, with a separate key (path) for each project and environment.
Create the state bucket first (with versioning on) and run terraform init to move state into it. Older setups use a DynamoDB table for locking instead.
Save yourself the pain
Common mistakes
Oops
Committing terraform.tfstate to Git so the team can share it.
Do this instead
Use a remote backend and add *.tfstate to .gitignore. Git has no locking, and the file can leak secrets.
Oops
Hand-editing the state file to fix a problem.
Do this instead
Use terraform state mv, state rm, import blocks or moved blocks. They change state safely and leave a record.
Your mission
Explore your state
Quick check
Two engineers run terraform apply on the same project at the same moment with no locking. What's the risk?
Go deeper
- 1Move a local state file to an S3 backend with encryption and versioning turned on.
- 2Enable state locking as described in the current Terraform S3 backend docs.
- 3Explain why the state file must never be committed to Git.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.