Agent skill · hashicorp
terraform-test
Comprehensive guide for writing and running Terraform tests. Use when creating test files (.tftest.hcl), writing test scenarios with run blocks, validating infrastructure behavior with assertions, mocking providers and data sources, testing module outputs and resource configurations, or troubleshooting Terraform test syntax and execution.
What it needs
About 6k tokens when loaded.
What this skill does
Terraform Test Terraform's built-in testing framework validates that configuration updates don't introduce breaking changes. Tests run against temporary resources, protecting existing infrastructure and state files. Reference Files references/MOCKPROVIDERS.md — Mock provider syntax, common defaults, when to use mocks (Terraform 1.7.0+ only — skip if the user's version is below 1.7) references/CICD.md — GitHub Actions and GitLab CI pipeline examples references/EXAMPLES.md — Complete example test suite (unit, integration, and mock tests for a VPC module) Read the relevant reference file when the user asks about mocking, CI/CD integration, or wants a full example. Core Concepts Test file (.tftest.hcl / .tftest.json): Contains run blocks that validate your configuration Run block: A single test scenario with optional variables, providers, and assertions Assert block: Conditions that must be true for the test to pass Mock provider: Simulates provider behavior without real infrastructure (Terraform 1.7.0+) Test modes: apply (default, creates real resources) or plan (validates logic only) File Structure Use unittest.tftest.hcl for plan-mode tests and integrationtest.tftest.hcl for apply-mode tests so they can be filtered separately in CI. Test File Structure Run Block Common Test Patterns Validate outputs Conditional resources Resource counts Tags Data sources Validation rules Sequential tests with dependencies Plan options (refresh-only, targeted) Parallel modules State key sharing Cleanup ordering (S3 objects before bucket) Multiple aliased providers Complex conditions Cleanup Resources are destroyed in reverse run block order after test completion. This matters for dependencies (e.g., S3 objects before bucket). Use terraform test -no-cleanup to skip cleanup for debugging. Running Tests Best Practices 1. Naming: unittest.tftest.hcl for plan mode, integrationtest.tftest.hcl for apply mode 2. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills hashicorp/terraform-test--4dd0d0