What this prompt does
This prompt writes Terratest tests in Go for a Terraform module that provisions [module_resources] on [cloud_provider], used across [environment_count] environments. It scaffolds the test file structure (test/[module_name]_test.go with TestMain for setup, per-scenario functions for [test_scenarios], and a shared helpers package), then a basic deployment test that runs init/plan/apply with [tfvars_overrides], validates outputs against expectations, and destroys, using t.Parallel() where possible.
The key value is real validation: for each critical resource it makes cloud SDK calls ([resource_validations]) to confirm resources are actually functional, not just that Terraform claims they exist. It adds retry logic via retry.DoWithRetry for [flaky_operations] with [max_retries] attempts and [retry_sleep] between them, defer terraform.Destroy plus [cleanup_extras] for resources Terraform might miss, random.UniqueId() naming for parallel runs, a [region_strategy] for test regions, and CI integration with [ci_system], a [test_timeout] per test, and auto-destroy after [max_age]. A module nobody tested is a module that breaks in production, so these checks call the cloud SDKs directly rather than trusting the plan.
When to use it
- You have a Terraform module you don't trust until it's tested against real cloud APIs
- You want validation that resources work, not just that the plan applied
- You need retries for flaky checks like ALB target registration or DNS propagation
- You want reliable cleanup even when tests fail partway
- You're running tests in parallel and need conflict-free resource naming
- You want CI integration with timeouts and automatic cost cleanup
- You're gaining confidence in a module before it touches production environments
Example output
The AI returns Go test files with terraform.Options and [tfvars_overrides], SDK-based validation functions for [resource_validations], retry.DoWithRetry wrappers for [flaky_operations], deferred destroy plus [cleanup_extras] logic, random.UniqueId() naming, and a CI config for [ci_system] with a [test_timeout] and auto-destroy after [max_age]. Expect Go code blocks grouped by the seven numbered concerns, so the validation and cleanup patterns are easy to reuse across modules.
Pro tips
- Validate functionality, not existence — use SDK calls in
[resource_validations](for example, an HTTP 200 from the ALB) rather than trusting Terraform output alone - Wrap genuinely flaky steps from
[flaky_operations]inretry.DoWithRetrywith sensible[max_retries]and[retry_sleep], since target registration and DNS take time - Always
defer terraform.Destroyso a failed assertion doesn't leave resources running and billing - Add
[cleanup_extras]for orphans Terraform misses, like leftover ENIs or CloudWatch log groups - Use
random.UniqueId()in naming so parallel tests don't collide on resource names - Shrink resources with
[tfvars_overrides](single AZ, smaller instances) so test runs stay cheap without changing the code path - Rotate test regions with
[region_strategy]so parallel runs spread API calls and don't trip per-region rate limits - Cap each test with
[test_timeout]and auto-destroy after[max_age]to control cost when CI hangs