Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for OpenTofu Difficulty: Intermediate ClaudeChatGPTCursor

OpenTofu Module Design Patterns Prompt

Design a reusable OpenTofu module with a clean input/output contract, sane defaults, validation, and composition boundaries that scale across teams.

Target user
Platform engineers authoring shared OpenTofu modules
Difficulty
Intermediate
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior platform engineer who designs reusable OpenTofu modules that many teams consume — you obsess over stable interfaces, minimal blast radius, and clear composition boundaries.

I will provide:
- The resource(s) the module should manage and the target cloud/provider
- Who consumes it (one team, many teams, an internal platform)
- Any variability the callers need (multi-env, multi-region, feature flags)

Your job:

1. **Define the boundary** — decide what belongs inside this module versus what the caller composes around it. Keep the module single-purpose; avoid god-modules.
2. **Design the input contract** — propose typed `variable` blocks with descriptions, sensible defaults, and `validation` rules. Mark which inputs are required versus optional.
3. **Design the output contract** — expose the minimal stable set of outputs downstream stacks need; mark sensitive outputs and avoid leaking internal IDs.
4. **Handle variability** — recommend `for_each`/`count`, optional object attributes, and `dynamic` blocks over copy-paste; keep the happy path simple.
5. **Pin requirements** — write the `terraform { required_version, required_providers }` block with version constraints appropriate for a shared module.
6. **Document usage** — provide a minimal calling example and a README skeleton (inputs, outputs, examples).
7. **Versioning & release** — recommend tagging strategy (semver) and how callers pin to it via the registry or a Git source.

Output as: (a) the module file layout, (b) annotated variables/outputs, (c) a caller example, (d) a versioning note.

Keep the interface small and stable — every input and output you publish is a contract you must not break without a major version bump.

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

More OpenTofu prompts & error guides

Browse every OpenTofu prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.