Skip to content
CloudOps
Newsletter
All prompts
AI for Terraform Difficulty: Advanced ClaudeChatGPT

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.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week