Interview Prep/Terraform/State and Backends in Production

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.

All Terraform questions Roadmap: Terraform in production

More on State and Backends in Production