Terraform Module Passed Provider Configuration Prompt
Correctly pass aliased provider configurations into a child module via configuration_aliases so multi-region or multi-account modules work without hidden provider inheritance.
- Target user
- Module authors building multi-region or multi-account modules
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Terraform engineer who builds modules that operate across multiple regions or accounts and passes provider configurations explicitly rather than relying on implicit inheritance.
I will provide:
- The module that needs more than one provider instance
- The root configuration's aliased providers
- The error or wrong-region behavior I am seeing
Your job:
1. **Diagnose the inheritance** — explain that a child module implicitly inherits the default provider unless you declare and pass aliases, which is why resources may land in the wrong region/account.
2. **Declare requirements** — add `configuration_aliases` inside the module's `required_providers` so the module formally requests named provider instances.
3. **Reference them** — show the resources/data sources inside the module using `provider = aws.<alias>` to bind to the passed config.
4. **Wire the root** — write the `providers = { aws = aws.primary, aws.replica = aws.replica }` mapping in the module call.
5. **Avoid anti-patterns** — explain why defining provider blocks inside the module breaks reusability and prevents clean destroys.
6. **Validate** — instruct me to run `terraform init` then `terraform plan` and confirm each resource targets the intended region/account.
7. **Document** — state which aliases the module expects so consumers can supply them.
Output as: (a) the module's required_providers with configuration_aliases, (b) example resource blocks, (c) the root module call with the providers map, (d) the verification steps.
Defining provider blocks inside a reusable module is discouraged because it blocks removal and reuse; review the plan to confirm placement before applying.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terraform Aliased Provider Passing to Nested Modules Prompt
Wire aliased providers (multi-region, multi-account) down through nested module trees using explicit `configuration_aliases` and `providers = {}` maps instead of implicit inheritance.
-
Terraform Multi-Region Fan-Out Design Prompt
Design a maintainable pattern for deploying the same stack across many regions using provider aliases and module fan-out — avoiding the dead-end where provider configurations cannot be created from `for_each` and copy-pasted per-region blocks proliferate.
-
Terraform Provider Configuration & Aliases Prompt
Configure Terraform providers — version constraints, aliases for multi-region/multi-account, required_providers.
-
Terraform for_each Set vs Map Keys Prompt
Decide whether a `for_each` should iterate a set of strings or a map of objects so instance keys stay stable, readable, and free of churn when the collection changes.
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.