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.
91
86%
Does it follow best practices?
Impact
100%
1.49xAverage score across 3 eval scenarios
Passed
No known issues
Test file naming and structure
tests/ directory
100%
100%
Unit test filename suffix
0%
100%
Integration test filename suffix
0%
100%
Unit tests use plan
0%
100%
Integration tests use apply
0%
100%
Descriptive run block names
100%
100%
Informative error messages
100%
100%
expect_failures for validation
100%
100%
Variable combinations covered
100%
100%
Assert conditions use can/regex
0%
100%
No git/HTTP module sources
100%
100%
Separate files created
100%
100%
Mock providers and sequential tests
mock_provider block used
100%
100%
mock_resource defaults
0%
100%
mock_data defaults
0%
100%
Mocks paired with plan mode
100%
100%
Sequential run reference
0%
100%
alltrue for expression
100%
100%
Conditional resource count test
100%
100%
expect_failures in mock test
100%
100%
Descriptive run block names
100%
100%
Specific error messages
87%
100%
Unit test filename
0%
100%
No apply with mocks
100%
100%
CI/CD pipeline configuration
Unit tests on PR trigger
100%
100%
Integration tests on main only
100%
100%
Unit test filter flag
66%
100%
Integration test filter flag
66%
100%
Credentials as secrets
100%
100%
No credentials in unit job
100%
100%
terraform fmt check step
0%
100%
terraform validate step
100%
100%
terraform init step
50%
100%
Verbose test output
87%
100%
Integration depends on unit
100%
100%
Valid CI config format
100%
100%
b129bb5
Table of Contents
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.