Sobes.tech
Junior — Middle

Where in Terraform is the infrastructure state usually stored?

sobes.tech AI

Answer from AI

In Terraform, the infrastructure state is usually stored in a file called terraform.tfstate. By default, this file is stored locally in the directory with the Terraform configuration.

For team collaboration and reliability, the state is often stored in remote backends, such as:

  • Terraform Cloud or Terraform Enterprise — HashiCorp cloud services.
  • Objects in cloud storage: for example, AWS S3, Google Cloud Storage, Azure Blob Storage.
  • HashiCorp Consul — a distributed key-value store.
  • Etcd or other supported backends.

Using a remote backend allows:

  • Sharing state among team members.
  • Protecting state with locks to prevent conflicts.
  • Automatically backing up the state.

Example configuration for AWS S3 backend:

terraform {
  backend "s3" {
    bucket = "my-terraform-state"
    key    = "path/to/my/key.tfstate"
    region = "us-east-1"
  }
}
Where in Terraform is the infrastructure state… - sobes.tech