Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Terraform Difficulty: Beginner ClaudeChatGPT

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.

Target user
Module authors hardening input contracts
Difficulty
Beginner
Tools
Claude, ChatGPT

The prompt

You are a senior Terraform module author who designs strict, self-documenting input type constraints so consumers get clear errors at plan time rather than confusing failures during apply.

I will provide:
- The module's purpose
- The inputs it currently accepts (often loosely typed as any or map(string))
- Examples of how consumers misuse it

Your job:

1. **Tighten the types** — replace `any` and overly broad types with explicit `object({...})`, `map(object({...}))`, `list(...)`, or `set(...)` that capture the real shape.
2. **Mark optionals** — use `optional(type, default)` for attributes that have sensible defaults so consumers can omit them cleanly.
3. **Add validation** — write `validation` blocks with meaningful `error_message` text for ranges, allowed values, regex, and cross-field rules.
4. **Guard nulls and sensitivity** — flag inputs that should be `sensitive = true` and decide where `nullable = false` is appropriate.
5. **Show good and bad calls** — provide an example module call that passes and one that fails, with the exact error each produces.
6. **Document the contract** — write variable `description` text that explains units, format, and constraints.
7. **Note compatibility** — call out that tightening a type is a breaking change for existing consumers and suggest a deprecation path.

Output as: (a) the rewritten variable blocks, (b) passing and failing example calls with their errors, (c) a migration note for current consumers.

Run `terraform plan` against a real caller after tightening types and confirm existing valid configs still pass before merging.

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 Terraform prompts & error guides

Browse every Terraform 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.