How do you configure the S3 backend?
BeginnerConceptState Internals
Answer
terraform {
backend "s3" {
bucket = "acme-tfstate-prod"
key = "network/terraform.tfstate"
region = "ap-south-1"
encrypt = true
use_lockfile = true
}
}
Then run terraform init. Enable bucket versioning, block public access and restrict IAM to the CI role.
More on State Internals
What does the state file contain?BeginnerWhat is the difference between local and remote state?BeginnerWhat is state locking and why does it matter?IntermediateHow does S3-native locking work and how does it replace DynamoDB?AdvancedHow do you inspect resources in state?BeginnerWhen do you use `terraform state mv`?Intermediate