Interview Prep/Terraform/Workflow and Providers

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 →

  1. Authenticate once (SSO or OIDC) into a tooling account.
  2. Configure assume_role in the provider, with the account ID as a variable.
  3. 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.

All Terraform questions Roadmap: Terraform

More on Workflow and Providers