Typorithm · medium

Remote State

terraform-remote-stateterraformbackendstatelocking
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Remote State

0%

State & Modules

A terraform backend "s3" block moves state off your laptop into a shared bucket, while dynamodb_table adds locking so two engineers can't apply at once.

By default Terraform writes terraform.tfstate locally, which breaks the moment a second person needs to apply — they have no copy of the truth.

A backend "s3" block stores that state in a shared bucket. bucket and key locate the object, and region tells Terraform how to reach it.

dynamodb_table turns on state locking: before an apply, Terraform writes a lock row; a concurrent apply sees the lock and waits, preventing the corruption two simultaneous writes would cause.

01

backend "s3" stores state remotely for the whole team.

02

bucket + key locate the state object.

03

dynamodb_table provides locking against concurrent applies.

terraform {
  backend "s3" {
    bucket         = "tf-state"
    key            = "prod/terraform.tfstate"
    region         = "us-east-1"
    dynamodb_table = "tf-locks"
  }
}

Read the implementation

Connect each part of the code to the concept before you type.

1. Backend declaration

The terraform block configures the backend that stores state; "s3" selects the remote backend type.

terraform {
  backend "s3" {

2. State bucket

bucket names the S3 bucket that holds the shared state file for the whole team.

bucket         = "tf-state"

3. State key

key is the object path inside the bucket, isolating this configuration's state from others.

key            = "prod/terraform.tfstate"

4. Bucket region

region tells Terraform where the S3 bucket lives so it can reach the backend.

region         = "us-east-1"

5. Lock table

dynamodb_table enables state locking; a lock entry blocks a second apply from running concurrently.

dynamodb_table = "tf-locks"

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Remote State: Lesson & Practice · Typorithm | ApplyDjinn