You must deploy the same stack into 12 AWS accounts. How do you handle credentials and provider configuration?
IntermediateScenarioWorkflow and Providers
Answer
Situation read → Many accounts means one identity assuming a role per target account, not 12 sets of keys.
What I'd do →
- Authenticate once (SSO or OIDC) into a tooling account.
- Configure
assume_rolein the provider, with the account ID as a variable. - Run one state per account (separate backend key or workspace per account), driven by a pipeline matrix.
provider "aws" {
region = var.region
assume_role {
role_arn = "arn:aws:iam::${var.account_id}:role/terraform-deploy"
session_name = "tf-${var.account_id}"
}
}
Why → Short-lived role sessions mean no long-lived keys, and per-account state keeps blast radius small.
Interview tip → Avoid for_each over providers in one state; provider aliases can't be dynamic in standard Terraform, so use one state per account.
More on Workflow and Providers
A new teammate is about to run Terraform for the first time against a shared dev account. Which commands do you walk them through, and in what order?BeginnerYour manager asks why we bother with `terraform plan` when `apply` shows the same diff before asking for confirmation. What do you say?BeginnerTwo engineers get different provider versions and see different plans for the same code. How do you stop this?BeginnerSomeone committed the `.terraform/` directory to the repo. What should be in version control and what should not?BeginnerThe same configuration must create a VPC in `us-east-1` and a DR copy of a bucket in `eu-west-1`. How do you do it with one root module?IntermediateHow do you make sure nobody runs your code with a Terraform version it wasn't tested against?Beginner