In a professional team environment, keeping the state file on your local machine (as we are doing in this lab) isn't ideal because others can't see it, and you might accidentally delete it. Remote State solves these problems.
Remote State is a feature that allows Terraform to write the state data to a remote, shared data store rather than your local disk.
Why Use Remote State?
- Team Collaboration: It creates a single "source of truth." When multiple people work on the same project, they all access the same state file from a central location.
- State Locking: Most remote backends support "locking." This prevents two people from running
terraform applyat the exact same time, which would corrupt the state file. - Security: State files often contain sensitive information (like passwords or private keys). Remote stores like AWS S3 or HashiCorp Cloud can encrypt the file at rest.
- Durability & Backups: Remote storage services usually offer versioning. If a state file gets corrupted, you can easily roll back to a previous version.
Common Remote Backends
Instead of a local file, you can configure Terraform to use:
- Terraform Cloud / Enterprise (HashiCorp's managed service)
- Amazon S3 (with DynamoDB for locking)
- Azure Blob Storage
- Google Cloud Storage
In short: Local State is for learning and solo experiments; Remote State is for real-world production work!