Give a pipeline in Account A access to state in a bucket in Account B.
IntermediateScenarioState Backends and Workspaces
Answer
Situation read → Cross-account backend access.
What I'd do →
- Create an IAM role in the state account with
s3:GetObject,PutObject,DeleteObject(for the lock file),ListBucketon the prefix. - Allow the pipeline role to assume it.
- Configure the backend with
assume_role.
backend "s3" {
bucket = "acme-tfstate"
key = "app/terraform.tfstate"
region = "ap-south-1"
assume_role = { role_arn = "arn:aws:iam::111111111111:role/tf-state-access" }
}
Why → The backend's identity is separate from the provider's, which keeps state access centralised and auditable.
Interview tip → Scope the role to the key prefix per stack.
More on State Backends and Workspaces
Two engineers keep overwriting each other's changes because state is local. What's the fix?BeginnerSet up a production-grade S3 backend. What do you configure for locking?IntermediateHow do you harden the S3 bucket that holds Terraform state?IntermediateWho creates the state bucket itself, given Terraform needs it to exist before `init`?IntermediateA laptop apply and a CI apply start at the same time. What stops state corruption?IntermediateWhen are Terraform workspaces appropriate?Beginner