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
