Model a Terraform provider alias to manage resources across multiple AWS accounts in a single root module using assume_role and distinct provider blocks

domain: Terraform · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Declare a default aws provider block for the management account and additional aliased provider blocks using provider "aws" { alias = "prod" } each with an assume_role block specifying the cross-account role ARN
  2. Pass the aliased provider to resources and modules using the provider meta-argument: provider = aws.prod; for modules, use providers = { aws = aws.prod } in the module call block
  3. Store account IDs and role ARNs in a locals block or variable map rather than hardcoding them; use a for_each on a map of account configs to generate per-account provider blocks dynamically where Terraform's provider meta-programming allows
  4. Configure the S3 backend with a single bucket in the management account and use workspaces or path prefixes to isolate state per account rather than running separate backends
  5. Add a data source in each aliased provider context to fetch the current caller identity and assert the expected account ID using a precondition block to fail fast if the wrong role is assumed
  6. In CI, supply credentials for the management account only and rely on assume_role chaining; add an iam:AssumeRole permission boundary on the automation role to limit blast radius

Known gotchas

Related routes

Configure Terraform to use the aws provider with multiple assume_role aliases for cross-account deployments in a single root module
terraform.io · 6 steps · unrated
Configure Crossplane ProviderConfig for multi-account AWS access using IAM role assumption per composite resource with selector-based config references
crossplane.io · 5 steps · unrated
Manage multi-environment Terraform state with Terragrunt remote_state blocks and path_relative_to_include
terragrunt.gruntwork.io · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans