cd ..
TERRAFORM

Terraform state - the file that can bring down your infrastructure

The terraform.tfstate is the map between your code and the real world. Lose the state, lose control of your infrastructure.

What the state stores

Every resource created, their real IDs in the cloud, dependencies, and metadata. This is how Terraform knows what to create, change, or destroy in a plan.

Why local state is dangerous

Remote Backend with S3

terraform {
  backend "s3" {
    bucket       = "meu-terraform-state"
    key          = "prod/network.tfstate"
    region       = "us-east-1"
    encrypt      = true
    use_lockfile = true
  }
}

After configuring:

terraform init -migrate-state
terraform plan

Golden Rules

  1. State always remote, versioned, and encrypted
  2. Never edit the state manually — use terraform state mv and similar commands
  3. One state per environment (dev/staging/prod separated)