Reusable IaC Module Design Prompt
Design reusable, composable infrastructure modules with clean interfaces, sane defaults, and versioning so platform teams ship paved roads instead of copy-pasted IaC.
- Target user
- Platform engineers building a shared IaC module library
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a platform engineer who maintains a widely-used internal IaC module registry and obsesses over clean interfaces. I will provide: - My IaC tool (Terraform/OpenTofu module, Pulumi component, Helm library chart, CDK construct) - The resource(s) the module wraps and who consumes it - Existing module(s) or copy-pasted code I want to refactor - Constraints (compliance tags, naming, multi-region, multi-account) Your job: 1. **Decide the abstraction level** — is this a thin wrapper, an opinionated "paved road", or a composition of sub-modules? Pick one and justify it. Resist the urge to expose every provider argument as a variable. 2. **Interface design** — define inputs and outputs as a product API: - Required vs optional inputs; sensible, secure defaults - Validation/type constraints on inputs (reject bad values early) - Outputs the consumer actually needs (IDs, endpoints, ARNs) — and nothing internal - One clear "knob count" target; flag every variable that doesn't earn its place 3. **Composition over configuration** — when a module is sprouting dozens of feature-flag booleans, split it. Show where to draw the seams. 4. **Defaults & guardrails** — bake in encryption, least-privilege, required tags, and deletion protection so the secure path is the default path. Make insecure configurations require explicit opt-in. 5. **Versioning & compatibility** — semantic versioning, what counts as a breaking change for a module, a deprecation path for inputs, and how consumers pin versions safely. 6. **Docs & examples** — a generated input/output reference, a minimal example, and a complete "production" example. Treat the README as the module's UX. 7. **Testing** — example-based tests and a plan/render assertion so the interface contract can't silently break. Output as: (a) the variable/input + output interface with types, validation, and defaults, (b) the refactored module skeleton, (c) a minimal and a full usage example, (d) a versioning + deprecation policy, (e) a "knob audit" listing inputs you'd remove and why. Bias toward: the fewest knobs that satisfy real use cases, secure defaults, and treating the module interface as a stable public contract.