liveBook · Manning

Remote state

As explained in Grokking Software Architecture

Remote state is infrastructure-as-code state stored in shared external storage rather than on an individual operator's local machine.

Terraform uses its state file to track existing infrastructure. Keep that file on one laptop, and a crash can leave resources unmanaged; have multiple people deploy at once, and their local files can conflict. Remote state stores the file in shared external storage instead. section 9.7.3

Shared storage and locking address two distinct risks:

  • Durable remote storage reduces the risk of losing the state file with one operator’s laptop. section 9.7.3
  • State locking prevents simultaneous deployments from overwriting each other: one deployment locks the file, and another must wait. section 9.7.3

Two developers, one deployment

A team stores its state in a central cloud bucket such as AWS S3. When Developer A starts a deployment, Terraform locks the remote file; if Developer B tries to deploy at the same time, Terraform asks them to wait. The team avoids a race over which state file is authoritative. section 9.7.3 section 9.12

How Grokking Software Architecture covers it

How deep it goes
Explains how durable cloud storage and locking address lost state and concurrent deployments.
Examples
Uses a crashed laptop, competing deployments, an AWS S3 bucket, and a database table for locking.
What you can do after
Operate team Terraform deployments with shared state storage and locking to avoid lost state and deployment collisions.
How it connects
Connects Terraform state files, infrastructure as code, and state locking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.