How do you configure the S3 backend to use a role in another account?
AdvancedProductionState and Backends in Production
Answer
terraform {
backend "s3" {
bucket = "acme-tfstate-shared"
key = "prod/app/terraform.tfstate"
region = "ap-south-1"
use_lockfile = true
assume_role = { role_arn = "arn:aws:iam::111111111111:role/tf-state-access" }
}
}
The role needs the bucket permissions above, and the bucket policy must trust it. The backend's credentials are separate from the AWS provider's, so you can state-access with one role and deploy with another.
More on State and Backends in Production
Why should Terraform state never be committed to Git?BeginnerHow do you bootstrap the remote backend, given the bucket must exist before Terraform can use it?IntermediateWhat does a hardened S3 state bucket look like?IntermediateWhat is the minimum IAM permission set for the S3 backend?IntermediateHow do you move from DynamoDB locking to S3 native locking in a live fleet?IntermediateState was deleted or corrupted. How do you recover?Advanced