terraform/website/docs/state/remote.html.md

2.3 KiB

layout page_title sidebar_current description
docs State: Remote Storage docs-state-remote Terraform can store the state remotely, making it easier to version and work with in a team.

Remote State

By default, Terraform stores state locally in a file named "terraform.tfstate". Because this file must exist, it makes working with Terraform in a team complicated since it is a frequent source of merge conflicts. Remote state helps alleviate these issues.

With remote state, Terraform stores the state in a remote store. Terraform supports storing state in Terraform Enterprise, Consul, S3, and more.

Remote state is a feature of backends. Configuring and using backends is easy and you can get started with remote state quickly. If you want to migrate back to using local state, backends make that easy as well.

Delegation and Teamwork

Remote state gives you more than just easier version control and safer storage. It also allows you to delegate the outputs to other teams. This allows your infrastructure to be more easily broken down into components that multiple teams can access.

Put another way, remote state also allows teams to share infrastructure resources in a read-only way.

For example, a core infrastructure team can handle building the core machines, networking, etc. and can expose some information to other teams to run their own infrastructure. As a more specific example with AWS: you can expose things such as VPC IDs, subnets, NAT instance IDs, etc. through remote state and have other Terraform states consume that.

For example usage see the terraform_remote_state data source.

Locking and Teamwork

Terraform will automatically lock state depending on the backend used. Please see the full page dedicated to state locking.

Terraform Enterprise by HashiCorp is a commercial offering that in addition to locking supports remote operations that allow you to safely queue Terraform operations in a central location. This enables teams to safely modify infrastructure concurrently.