Backends Overview
Backends define where Terraform stores state data files. By default, Terraform uses the “local” backend, which stores state files on the local filesystem. Remote backends allow you to store state remotely, enable team collaboration, and provide state locking.What is a Backend?
A backend in Terraform determines:- Where state is stored - The location of your Terraform state file
- How operations are executed - Whether operations run locally or remotely
- State locking - Prevention of concurrent state modifications
- State versioning - Historical tracking of state changes
Backend Interface
All backends implement the core backend interface defined in/internal/backend/backend.go:44-106:
Default Workspace
Every backend must have a default workspace named"default" (constant DefaultStateName). This workspace cannot be deleted.
Available Backends
Terraform supports the following backends:Local Backend
- Local - Stores state on the local filesystem
Cloud Storage Backends
- S3 - Amazon S3
- Azure - Azure Blob Storage
- GCS - Google Cloud Storage
- OSS - Alibaba Cloud OSS
- COS - Tencent Cloud COS
- OCI - Oracle Cloud Infrastructure Object Storage
Database Backends
Kubernetes Backend
- Kubernetes - Kubernetes secrets
Generic Backend
- HTTP - REST API endpoints
Choosing a Backend
Consider these factors when selecting a backend:- Team Size - Remote backends enable collaboration
- Infrastructure - Use backends compatible with your existing infrastructure
- Security - Consider encryption, access controls, and compliance requirements
- Reliability - Ensure high availability and disaster recovery
- Cost - Evaluate storage and operation costs
Workspace Support
Most backends support multiple workspaces, allowing you to manage multiple states within a single backend configuration. The HTTP backend does not support workspaces.State Locking
State locking prevents concurrent modifications. Most remote backends support state locking:- S3 - Uses DynamoDB for locking (legacy) or lock files
- Azure - Uses blob leases
- GCS - No built-in locking
- Consul - Native locking support
- Postgres - Database-level locking
- Kubernetes - Uses Lease objects
- HTTP - Optional locking via custom endpoints