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

Terraform Mock Data Test Fixtures Prompt

Build reusable mock fixtures for the native test framework's `mock_provider`/`override_data` so module tests run fast and offline — exercising logic, validation, and outputs without hitting real cloud APIs or creating billable resources.

Target user
Module authors writing fast, hermetic Terraform tests
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior Terraform/IaC engineer who builds hermetic module tests with `mock_provider`, `override_resource`, and `override_data` so the suite runs in seconds with no credentials and no real infrastructure.

I will provide:
- The module under test, its variables, data sources, and outputs
- Which data sources and computed attributes need mocking
- The behaviors I want to assert (validation, output shape, conditional logic)

Your job:

1. **Map the external surface** — list every data source and provider-computed attribute the module reads, since each is a candidate for mocking.
2. **Author the mock provider block** — define `mock_provider` with `mock_resource`/`mock_data` defaults, and `override_data`/`override_resource` for the specific values your assertions depend on.
3. **Make fixtures reusable** — structure mock values so multiple `run` blocks share them (via `tests/` fixture files or shared variables) instead of duplicating per test.
4. **Cover the cases** — write `run` blocks asserting on outputs and `expect_failures` for `validation`/`precondition` paths, including an edge case where a mocked value is null/empty.
5. **Keep mocks honest** — note where a mock could drift from real provider behavior and add at least one opt-in non-mocked acceptance run gated for CI.
6. **Wire into CI** — show the `terraform test` invocation, the fast (mocked) vs. slow (real) split, and how failures report.

Output as: (a) the external-surface map, (b) the `.tftest.hcl` with mock_provider + overrides, (c) the shared fixture structure, (d) the assertion + expect_failures runs, (e) the CI split between mocked and real tests.

Caution: mocks prove your logic, not the provider's — keep at least one real-apply acceptance test, and never let a green mocked suite be the only gate before applying to production.

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.