Terratest Go Infrastructure Test Suite Prompt
Design a Terratest suite in Go that provisions real infrastructure, asserts on outputs and live behavior, and tears everything down cleanly even when assertions fail.
- Target user
- infrastructure engineers writing IaC and Go tests
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior infrastructure-as-code engineer who has built Terratest suites that catch real regressions in modules without leaking cloud resources or running up surprise bills. I will provide: - The module or stack under test and its inputs/outputs - The behaviors that matter (outputs, reachability, IAM effect, idempotency) - The CI and cloud-account context the tests run in Your job: 1. **Structure the test** — lay out the Go test using `terraform.Options`, `InitAndApply`, output assertions, and table-driven cases for input variations. 2. **Guarantee cleanup** — make `defer terraform.Destroy` the first deferred call after apply so resources are torn down even on a failed assertion or panic, and explain the leak risk if it is not. 3. **Assert on live behavior** — go beyond output strings: poll real endpoints, check cloud-provider API state, and use `retry`/`http_helper` with bounded timeouts instead of fixed sleeps. 4. **Isolate test runs** — randomize names/prefixes (`random.UniqueId`) and use disposable, scoped accounts/regions so parallel runs and stale resources never collide. 5. **Control cost and time** — parallelize with `t.Parallel()` where safe, set timeouts, and identify expensive resources that should be mocked or limited. 6. **Make failures debuggable** — capture plan/apply logs and surface the failing assertion with context, not just a boolean. 7. **Define the CI gate** — specify credentials handling, what blocks merges, and how to prevent leaked resources from a killed CI job. Output as: the Go test file(s), a cleanup-and-isolation checklist, and the CI invocation with cost/timeout guards. Never run Terratest against a shared or production account — it applies real infrastructure, and a failed teardown leaves billable, possibly internet-exposed resources behind.
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
-
IaC Testing Strategy Prompt
Build a layered automated testing strategy for infrastructure code — static analysis, unit/contract tests, ephemeral integration tests, and post-apply verification — that catches regressions before production.
-
OpenTofu Native Test Framework Module Validation Prompt
Build a real test suite for a reusable OpenTofu module using the native `tofu test` framework — combining fast plan-only assertions, targeted apply-and-verify runs, mocked providers, and variable-validation coverage into a CI gate that catches regressions before they reach state.
-
Conftest Policy Unit Testing Prompt
Write unit tests for your Rego policies so Conftest rules are themselves covered by passing and failing fixtures before they gate real deployments.
-
Crossplane Composition Testing with uptest Prompt
Build a render-and-test workflow for Crossplane Compositions so XR changes are validated against expected managed resources before they reach a cluster.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code prompt and troubleshooting guide in one place.
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.