What if your infrastructure state got lost or overwritten just because it was saved on your computer?
Why S3 backend configuration in Terraform? - Purpose & Use Cases
Imagine you are managing your infrastructure code on your own computer. Every time you make a change, you save the state file locally. Now, your team members also want to work on the same project, but they have different copies of the state file. This causes confusion and mistakes.
Keeping the state file on your local machine is slow and risky. If the file gets lost or corrupted, you lose track of your infrastructure. Also, when multiple people work together, they might overwrite each other's changes without knowing.
Using an S3 backend means storing the state file safely in the cloud. Everyone on the team accesses the same file, so changes are tracked and shared automatically. This avoids conflicts and keeps your infrastructure reliable.
terraform init
terraform apply
# state saved locally in terraform.tfstateterraform {
backend "s3" {
bucket = "my-terraform-state"
key = "project/terraform.tfstate"
region = "us-east-1"
}
}
terraform initIt enables safe, shared, and reliable management of infrastructure state across teams using cloud storage.
A team building a website uses S3 backend so all developers see the latest infrastructure state, preventing accidental overwrites and lost updates.
Local state files cause confusion and risk.
S3 backend stores state centrally and securely.
Teams can collaborate smoothly without conflicts.