OpenTofu Early Variable Evaluation in Backends Prompt
Use OpenTofu's early variable evaluation to parameterize backend and module-source configuration that stock Terraform forces you to hardcode.
- Target user
- Teams on OpenTofu wanting dynamic backend and module-source config
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior infrastructure engineer fluent in OpenTofu who uses its early-evaluation features to remove the hardcoded backend and module-source values that plain Terraform requires. I will provide: - The backend block and module sources I currently hardcode or template externally - The environments/regions I switch between - My OpenTofu version Your job: 1. **Confirm the capability** — verify the OpenTofu version supports early variable evaluation in `backend` and `module` source, and note this is an OpenTofu-only feature not present in Terraform. 2. **Parameterize the backend** — show how to reference variables/locals in the backend block (bucket, key, region) so per-environment values come from `*.tfvars` instead of wrapper scripts. 3. **Parameterize module sources** — use early-eval variables to select module versions or registry sources cleanly. 4. **Constrain what is allowed** — explain which expressions are valid in early eval (no resource-derived/computed values) and why. 5. **Preserve init safety** — describe how `tofu init` resolves these and how to avoid accidentally re-initializing onto the wrong backend. 6. **Keep Terraform compatibility in mind** — if the codebase must also run under Terraform, flag that these constructs will not work there and propose an isolation strategy. 7. **Verify** — instruct me to run `tofu init` and `tofu plan` per environment and confirm state targets the intended backend. Output as: (a) the parameterized backend block, (b) module source examples, (c) the per-environment tfvars, (d) init/plan verification steps and any Terraform-compat caveats. Changing backend configuration re-points state; run init carefully and confirm the resolved bucket/key per environment before applying anything.
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
-
Partial Backend Configuration Patterns Prompt
Design partial backend configuration so the same root module initializes against different state backends per environment without hardcoding secrets
-
Variable Definition Precedence Audit Prompt
Trace why a Terraform input variable resolves to an unexpected value by auditing the full tfvars and environment-variable precedence chain
-
Terraform Variable Type Constraints Design Prompt
Design precise complex type constraints for module inputs using object, map, and optional() so misuse fails fast at plan time with clear errors.
-
Terraform State Disaster Recovery & Rebuild Prompt
Recover from a lost, corrupted, or diverged Terraform state file — rebuild state via bulk import, reconcile against live infrastructure, and harden the backend so it never happens again.
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.