CICD-238 · Terraform remote state configuration
Encyclopedia · Terraform and infrastructure as code · All snippets
Previous · CICD-237 · Next · CICD-239
1. Where it fits
- Placement backend.tf.
- Prerequisites trusted Linux runner, Terraform CLI, reviewed IaC and a disposable state for writes.
- Platforms local-lab.
2. Copy the snippet
hcl
terraform {
backend "s3" {
bucket = "replace-dedicated-terraform-state"
key = "staging/service.tfstate"
region = "eu-west-2"
encrypt = true
use_lockfile = true
}
}3. How it works
The backend selects one encrypted S3 object key for state and enables supported lockfile-based concurrency control. Provision bucket access and versioning separately.
4. Verify the result
Enable bucket versioning and restrictive IAM. The S3 lockfile option requires a Terraform version that supports it.
Validation version-dependent. Status definitions.