Skip to content
CloudOps
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPT

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.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week