Terraform S3 backend
(Redirected from S3 Backend)
Jump to navigation
Jump to search
Make sure you enable Bucket Versioning on the S3 bucket
profile: https://www.terraform.io/docs/language/settings/backends/s3.html#profilekey: path to the state file inside the S3 Bucket. https://www.terraform.io/docs/language/settings/backends/s3.html#keyuse_lockfile(ref).tflockdynamodb_table, useuse_lockfile
Contents
Basic S3 examples in backend.tf[edit]
terraform {
backend "s3" {
bucket = "your-terraform-states"
key[1] = "terraform.tfstate"
profile = "your-profile"
}
}
https://www.terraform.io/docs/language/settings/backends/s3.html#example-configuration
terraform {
backend "s3" {
bucket = "mybucket"
key = "path/to/my/terraform.tfstate"
encrypt = true
region = "us-east-1"
}
}
#This simple example will prompt you for bucket name once you executed terraform init terraform { backend "s3" { } }
Example including DynamoDB table[edit]
terraform {
backend "s3" {
bucket = "your-terraform-states"
key[2] = "terraform.tfstate"
region = "us-west-2"
dynamodb_table = "your-terraform-states"
profile = "your-profile"
workspace_key_prefix = "your-workspace"
}
}
profile: https://www.terraform.io/docs/language/settings/backends/s3.html#profilekey: path to the state file inside the S3 Bucket. https://www.terraform.io/docs/language/settings/backends/s3.html#key
Successfully configured the backend "s3"! Terraform will automatically use this backend unless the backend configuration changes. Error refreshing state: AccessDenied: Access Denied status code: 403, request id: JDK297FD1E5GY3TT, host id: JJJ1ThvIKmNSYOO3h2IZFECn9l8DnsofwXWk4F6a9/nzrqgNNbOzyw9d2PcAXSb4DDYwkr/VNWZ0
S3 backend errors[edit]
Error: Backend configuration changedError: Failed to get existing workspaces: S3 bucket does not exist.:aws s3 mbError: no valid credential sources for S3 Backend found
Changelog[edit]
Related terms[edit]
terraform init- Remote state backends to manage Terraform state
terraform_remote_statedata sourceaws s3api create-bucketandaws s3 mbaws s3 lsprovider.tf- Terraform backend: gcs
See also[edit]
- Terraform S3 backend:
use_lockfile,.tflock - Terraform backends:
S3,dynamodb_table,GCS,remote(Terraform Cloud),backend.tf,http
Advertising: