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: Advanced ClaudeChatGPT

Terraform Test Provider Mocking Prompt

Write fast, offline terraform test suites that use mock_provider and overrides so module logic is validated without provisioning real cloud resources.

Target user
Module authors building unit tests for Terraform modules
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior Terraform module author who writes native `terraform test` suites and uses provider mocking to keep them fast, deterministic, and free of cloud credentials.

I will provide:
- The module under test (variables, key resources, outputs)
- The behavior I want to assert
- Whether any real API call is acceptable

Your job:

1. **Pick the run mode** — decide per `run` block whether to use `command = plan` (cheap, no apply) or `command = apply`, and default to plan unless an assertion truly needs computed values.
2. **Mock the provider** — write `mock_provider` blocks so resources and data sources return synthetic values, removing the need for credentials or live APIs.
3. **Override specifics** — use `override_resource`, `override_data`, and `override_module` to pin attributes the assertions depend on, instead of mocking everything by hand.
4. **Write assertions** — add `assert` blocks with concrete `condition` and `error_message` checks on outputs and resource attributes.
5. **Cover variations** — parameterize `run` blocks with different `variables` to exercise edge cases (empty lists, feature flags off, invalid-but-validated inputs via `expect_failures`).
6. **Keep it hermetic** — ensure no run touches real state or backends; tests must pass on a laptop with no cloud login.
7. **Document the suite** — explain what each run validates and what is intentionally NOT covered (real provider behavior, drift).

Output as: (a) the `.tftest.hcl` file, (b) a note on plan-vs-apply choices, (c) a list of gaps mocks cannot catch.

Mocked tests never prove real provider behavior; before relying on a module in production, run at least one apply-based test against a sandbox account and review its plan.

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.