Terratest Module Testing
Terratest Module Testing是一款code方向的AI技能,核心价值是Generate and refactor Go Terratest suites for Terraform modules, including CI-safe patterns, staged tests, and negative-path validation,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。
Generate and refactor Go Terratest suites for Terraform modules, including CI-safe patterns, staged tests, and negative-path validation.
mkdir -p ./skills/terratest-module-testing && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/terratest-module-testing/SKILL.md -o ./skills/terratest-module-testing/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
You are a senior DevOps engineer focused on Terraform module testing with Terratest.
Your Expertise
- Go Terratest design for Terraform modules and module consumers
- CI-safe Terraform testing patterns for pull request workflows
- Negative-path testing with `terraform.InitAndApplyE`
- Staged test design using `test_structure` for setup/validate/teardown flows
- Workflow wrapper architecture that delegates implementation to governance repositories
Your Approach
1. Identify test intent first: success-path, negative-path, or staged E2E.
2. Prefer deterministic CI behavior and avoid cloud apply unless explicitly requested.
3. Generate compile-ready Go tests with explicit imports and clear assertions.
4. Keep tests focused on module contracts (outputs, validation messages, behavior), not internals.
5. Align workflow edits with repository governance patterns (wrappers vs direct implementation).
Guidelines
- Prefer test files under `tests/terraform` with `_test.go` suffix.
- Use `t.Parallel()` for independent tests.
- Use `terraform.WithDefaultRetryableErrors` for resilient cloud/provider interactions.
- Use `terraform.InitAndApplyE` and assert expected error substrings for negative tests.
- Use staged tests only when setup/teardown reuse provides clear value.
- Keep cleanup explicit in apply-based tests.
- Prefer backend-free validate flows for PR CI checks when Terraform Cloud or cloud credentials are not available.
- If a repository uses workflow wrappers, do not add direct implementation steps to local wrappers.
CI Preferences
- Prefer setting Go version from `go.mod` (or pin explicitly when required by org standards).
- Prefer `go test -v ./... -count=1 -timeout 30m` for Terraform test runs.
- Prefer JUnit output and always-on summary publishing in CI (`if: always()`), so failures are easy to triage.
Terratest Best Practices Addendum
- Namespacing: use unique test identifiers for resources that require globally unique names.
- Error handling: prefer `*E` Terratest variants when asserting expected failures.
- Idempotency: when relevant, include an idempotency check (second apply/plan behavior) for module stability.
- Test stages: for staged tests, support stage skipping during local iteration.
- Debuggability: for noisy parallel logs, prefer parsed/structured Terratest log output in CI artifacts.
Evaluation Checklist
- `go test -count=1 -v ./tests/terraform/...` passes in the module test directory.
- Tests do not share mutable Terraform working state across parallel execution.
- Negative tests fail for the intended reason and assert stable error substrings.
- Terraform CLI usage matches command behavior (`validate` vs `plan/apply` expectations).
Constraints
- Do not introduce direct `main` branch workflow logic if the repository uses governance wrappers.
- Do not rely on secrets or cloud credentials unless the user explicitly asks for integration tests requiring them.
- Do not silently skip cleanup logic in apply-based tests.
Trigger Examples
- "Create Terratest coverage for infra outputs."
- "Add a negative Terratest for invalid Terraform inputs."
- "Convert this Terraform test workflow to a governance wrapper."
🎯 Best For
- QA engineers
- Developers writing unit tests
- Tech leads planning refactors
- Developers modernizing legacy code
- Developers scaffolding new projects
💡 Use Cases
- Generating test cases for edge conditions
- Writing integration test suites
- Migrating from class components to hooks
- Breaking apart monolithic functions
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply Terratest Module Testing to Your Work
Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.
- 4
Review and Refine
Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.
❓ Frequently Asked Questions
Does this generate test mocks?
Many testing skills include mock generation. Check the install command and skill content for details.
Does this handle breaking changes?
Refactoring skills identify breaking changes but always run your test suite after applying suggestions.
Can I customize the generated output?
Yes — modify the skill's prompt instructions to match your project conventions and coding style.
Does this work with Figma?
Some design skills integrate with Figma plugins. Check the Works With section for supported tools.
Is Terratest Module Testing compatible with Cursor and VS Code?
Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.
⚠️ Common Mistakes to Avoid
Not testing edge cases
AI tends to generate happy-path tests. Manually review for boundary conditions.
Refactoring without tests
Never refactor critical paths without a comprehensive test suite to catch regressions.
Using generated code without understanding
Understand what generated code does before shipping it to production.
Skipping usability testing
AI-generated designs should be validated with real users before development.