Thuta Learning
Terraform
AdvancedDevOpsIntermediate

Remote State & Backends

TerraformLesson 15

What you'll walk away with

  • Understand Remote State & Backends without any of the intimidation
  • Get hands-on running terraform commands and HCL code yourself
  • Apply this concept in a real project right away

Let's think about it this way for a second

Local state (the default) only lives on one laptop — other team members can't see it, and if two people apply at the same time the state file can get split apart. A Remote Backend (`backend "s3" { ... }`) stores the state file in a shared location (an S3 bucket, Terraform Cloud), so every team member always sees the latest state. State Locking (typically a DynamoDB table paired with an S3 backend) locks things so no one else can apply while someone else's apply is in progress — protecting against state corruption.

Let's connect this to a real scenario

If you configure `terraform { backend "s3" { bucket = "my-terraform-state"; key = "prod/terraform.tfstate"; region = "us-east-1"; dynamodb_table = "terraform-locks" } }`, running `terraform init` migrates the state from local to S3 — after that, any team member running `terraform apply` from the same config folder will always get the latest state.

Let's look at it together

hcl
terraform {
  backend "s3" {
    bucket         = "my-terraform-state"
    key            = "prod/terraform.tfstate"
    region         = "us-east-1"
    dynamodb_table = "terraform-locks"
    encrypt        = true
  }
}
You should see
$ terraform init
Initializing the backend...

Successfully configured the backend "s3"! Terraform will
automatically use this backend unless the backend configuration
changes.

5-minute try-it

Write a remote backend config (S3 or whichever provider you're familiar with) and study Terraform's prompts/output when it configures the backend — don't actually create cloud resources, just do a dry-run/documentation review.

A quick word of caution

If the S3 bucket (state storage) accidentally becomes publicly accessible, every bit of sensitive data (passwords, secrets) inside can leak — keep the bucket private and enable encryption.

Easy traps

  • Skipping remote backend setup and trying to share a local state file with the team via a git commit — this leads to merge conflicts and can corrupt the state
  • Using an S3 backend without setting up state locking (a DynamoDB table) — without locking, concurrent applies can corrupt the state

Now try it yourself

Write a remote backend config (S3 or whichever provider you're familiar with) and study Terraform's prompts/output when it configures the backend — don't actually create cloud resources, just do a dry-run/documentation review.

You'll know it worked when: $ terraform init Initializing the backend... Successfully configured the backend "s3"! Terraform will automatically use this backend unless the backend configuration changes.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Remote State & Backends | Thuta Learning