S3 Backend
The S3 backend stores state as a given key in a given S3 bucket on Amazon Web Services (AWS). This backend supports state locking and consistency checking via DynamoDB.Implementation
Location:/internal/backend/remote-state/s3/backend.go
Use Cases
- Team collaboration on AWS infrastructure
- Production environments requiring state locking
- Integration with AWS-based CI/CD pipelines
- Compliance requirements for data residency
Basic Configuration
Required Configuration
bucket
- Type: String
- Required: Yes
- Description: The name of the S3 bucket
key
- Type: String
- Required: Yes
- Description: The path to the state file inside the bucket
- Be empty
- Contain
//(double slashes) - Start or end with
/
region
- Type: String
- Optional: Yes (if environment variables are set)
- Environment Variables:
AWS_REGION,AWS_DEFAULT_REGION - Description: AWS region of the S3 bucket and DynamoDB table
Authentication
The S3 backend supports multiple authentication methods:Static Credentials
- Access Key:
AWS_ACCESS_KEY_ID - Secret Key:
AWS_SECRET_ACCESS_KEY
Shared Credentials File
AWS_SHARED_CREDENTIALS_FILEAWS_SHARED_CONFIG_FILE
IAM Role Assumption
- role_arn (Required) - The ARN of the IAM role to assume
- session_name (Optional) - The session name to use
- duration (Optional) - Duration between 15m and 12h (default: 1h)
- external_id (Optional) - External ID for the role
- policy (Optional) - IAM policy JSON to restrict permissions
- policy_arns (Optional) - Set of policy ARNs to attach
- tags (Optional) - Map of session tags
- transitive_tag_keys (Optional) - Set of tag keys to pass to subsequent sessions
Web Identity Token
Encryption
Server-Side Encryption (SSE-S3)
KMS Encryption (SSE-KMS)
Customer-Provided Encryption (SSE-C)
AWS_SSE_CUSTOMER_KEY
Note: You cannot use both kms_key_id and sse_customer_key simultaneously.
State Locking
DynamoDB Locking (Deprecated)
dynamodb_table attribute is deprecated in favor of use_lockfile.
Lock File (Recommended)
Workspaces
The S3 backend supports workspaces using a key prefix:"env:"
With workspace production, the state is stored at:
Advanced Configuration
Custom Endpoints
Path-Style URLs
https://s3.amazonaws.com/bucket/key instead of https://bucket.s3.amazonaws.com/key.
Skip Validations
ACL Configuration
All Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
bucket | string | Yes | S3 bucket name |
key | string | Yes | Path to state file in bucket |
region | string | Yes* | AWS region |
access_key | string | No | AWS access key |
secret_key | string | No | AWS secret key |
token | string | No | MFA token |
profile | string | No | AWS profile name |
shared_credentials_files | list(string) | No | Paths to credentials files |
encrypt | bool | No | Enable server-side encryption |
kms_key_id | string | No | KMS key ARN |
sse_customer_key | string | No | Customer-provided encryption key |
acl | string | No | Canned ACL for state file |
dynamodb_table | string | No | DynamoDB table for locking (deprecated) |
use_lockfile | bool | No | Use lock file for state locking |
workspace_key_prefix | string | No | Prefix for workspace state paths |
skip_credentials_validation | bool | No | Skip credentials validation |
skip_region_validation | bool | No | Skip region validation |
skip_s3_checksum | bool | No | Skip S3 checksum validation |
use_path_style | bool | No | Use path-style S3 URLs |
use_fips_endpoint | bool | No | Use FIPS endpoints |
use_dualstack_endpoint | bool | No | Use dual-stack endpoints |