Overview

The default backend type that ships with Terraform is the local backend. Using the local backend means that the Terraform state file has to be locally managed. When working with Terraform, especially as a team of engineers, it’s important to have a way to store and share the state of our infrastructure in a consistent manner. Terraform backends provide the ability to store the Terraform state in other remote locations that can be accessed by team members in a concurrent and collaborative manner. Using Terraform backends helps ensure that the state file, which contains the current state of our infrastructure, is securely stored and accessible. Some of the benefits of using remote Terraform backends include the following:

  • Remote state locking: This prevents the Terraform state from being modified by two individuals at the same time.

  • Wide storage options: This allows users to take advantage of different storage options provided by a number of cloud providers like Amazon, Microsoft, Google, and so on.

  • Concurrent access: This helps ensure that configuration files can be worked on by different team members at the same time.

  • Consistent storage: This helps ensure a level of redundancy as the state file is kept safe and can be used to recover the infrastructure setup in case of accidental deletion.

  • Access control: Remote backends allow user permissions and restrictions to be defined.

Common types of backends

Terraform provides the option of working with various backend types ranging from local to remote. These backend types include the following.

  • Local backend
  • S3 backend
  • Azure Blob Storage backend
  • Terraform Cloud backend
  • Consul backend

When working with Terraform on our local systems, we don’t need to configure a backend explicitly because the default backend is local. However, while using a remote backend, some settings are necessary. The basic syntax for configuring a remote backend is shown below:

Get hands-on with 1200+ tech skills courses.