Terratest Module Testing
GitHubOfficialFirst committed by ZdaPhpDistributed by GitHub
- Custom agent
- Content generator
- Cloud and DevOps
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Terratest Module Testing acts as a senior DevOps engineer to assist in designing, generating, and refactoring Go-based Terratest suites for Terraform modules. It focuses on creating robust, CI-ready test code that covers success paths, negative-path validation, and staged end-to-end testing. The skill emphasizes modularity, idempotency, and adherence to repository governance patterns, ensuring that infrastructure tests are reliable, maintainable, and well-integrated into automated pull request workflows.
What it does
- Generates compile-ready Go Terratest code for Terraform modules.
- Implements negative-path testing using error assertion patterns.
- Designs staged test flows using test_structure for complex setup and teardown.
- Ensures CI-safe testing patterns that avoid state conflicts in parallel execution.
- Provides guidance on integrating tests with existing repository governance wrappers.
- Includes idempotency checks to verify module stability across multiple applies.
When to use it
- When you need to write automated tests for new Terraform modules.
- When you need to validate that your Terraform module correctly handles invalid inputs.
- When you need to refactor existing tests to be more resilient in CI environments.
- When you need to implement staged tests that require specific setup and teardown sequences.
- When you need to ensure your testing approach aligns with organizational governance standards.
Advantages
- Promotes deterministic and reliable CI test behavior.
- Reduces manual effort in writing boilerplate Go test code.
- Ensures consistent error handling and resource cleanup across test suites.
- Facilitates better debugging through structured log output and JUnit reporting.
- Supports complex testing scenarios like idempotency and negative-path validation.
Usage examples
- “Create Terratest coverage for infra outputs.”
- The agent generates a Go test file that initializes the Terraform module, applies the configuration, and asserts that the module outputs match the expected values.
- “Add a negative Terratest for invalid Terraform inputs.”
- The agent provides a test snippet using InitAndApplyE that intentionally passes invalid variables and asserts that the expected error message is returned by Terraform.
- “Convert this Terraform test workflow to a governance wrapper.”
- The agent refactors the test implementation to delegate logic to the repository's established governance wrappers instead of using direct local implementation.
Install
Download the custom agent as a ZIP:
https://mp-staging.autogineer.com/agent-skills/github/terratest-module-testing/downloadExtract the agent file into .github/agents, then commit it:
mkdir -p .github/agents && unzip -j terratest-module-testing.zip 'terratest-module-testing/terratest-module-testing.agent.md' -d .github/agentsKeep the LICENSE and ATTRIBUTION.md files from the ZIP with your copy.
Documentation by ZdaPhp
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.InitAndApplyEStaged test design using
test_structurefor setup/validate/teardown flowsWorkflow wrapper architecture that delegates implementation to governance repositories
Your Approach
Identify test intent first: success-path, negative-path, or staged E2E.
Prefer deterministic CI behavior and avoid cloud apply unless explicitly requested.
Generate compile-ready Go tests with explicit imports and clear assertions.
Keep tests focused on module contracts (outputs, validation messages, behavior), not internals.
Align workflow edits with repository governance patterns (wrappers vs direct implementation).
Guidelines
Prefer test files under
tests/terraformwith_test.gosuffix.Use
t.Parallel()for independent tests.Use
terraform.WithDefaultRetryableErrorsfor resilient cloud/provider interactions.Use
terraform.InitAndApplyEand 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 30mfor 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
*ETerratest 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 (
validatevsplan/applyexpectations).
Constraints
Do not introduce direct
mainbranch 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."
Files
- ATTRIBUTION.mdAdded by AutoGineer886 B
- LICENSELicence file added by AutoGineer1.0 KiB
- terratest-module-testing.agent.md3.4 KiB
LICENSE
MIT License Copyright GitHub, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Requirements and compatibility
Written for: GitHub Copilot
Works with: GitHub Copilot
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- First committed by
ZdaPhp
- Publisher
- GitHub (Official)
- Distributed by
- GitHub
- Source
- github/awesome-copilot · agents/terratest-module-testing.agent.md · commit 797337f
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
- Contributors
- ZdaPhp
AutoGineer is not affiliated with or endorsed by ZdaPhp or GitHub.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download terratest-module-testing.zip