comeonoliver/skillshub/terraform-test
Claude Code and agent skill by comeonoliver/skillshub
- community
- ext:[{"type":"config","description":"Configuration overrides"}]
Checking that the SKILL.md file is still in the repository.
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.
Install
npx vskill@latest install comeonoliver/skillshub/terraform-testSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as comeonoliver/skillshub/terraform-test.
Terraform Test
Terraform's built-in testing framework enables module authors to validate that configuration updates don't introduce breaking changes. Tests execute against temporary resources, protecting existing infrastructure and state files.
Core Concepts
Test File: A .tftest.hcl or .tftest.json file containing test configuration and run blocks that validate your Terraform configuration.
Test Block: Optional configuration block that defines test-wide settings (available since Terraform 1.6.0).
Run Block: Defines a single test scenario with optional variables, provider configurations, and assertions. Each test file requires at least one run block.
Assert Block: Contains conditions that must evaluate to true for the test to pass. Failed assertions cause the test to fail.
Mock Provider: Simulates provider behavior without creating real infrastructure (available since Terraform 1.7.0).
Test Modes: Tests run in apply mode (default, creates real infrastructure) or plan mode (validates logic without creating resources).
File Structure
Terraform test files use the .tftest.hcl or .tftest.json extension and are typically organized in a tests/ directory. Use clear naming conventions to distinguish between unit tests (plan mode) and integration tests (apply mode):
Test File Components
A test file contains:
- Zero to one
testblock (configuration settings) - One to many
runblocks (test executions) - Zero to one
variablesblock (input values) - Zero to many
providerblocks (provider configuration) - Zero to many
mock_providerblocks (mock provider data, since v1.7.0)
Important: The order of variables and provider blocks doesn't matter. Terraform processes all values within these blocks at the beginning of the test operation.
Test Configuration (.tftest.hcl)
Test Block
The optional test block configures test-wide settings:
Test Block Attributes:
parallel- Boolean, when set totrue, enables parallel execution for all run blocks by default (default:false). Individual run blocks can override this setting.
Run Block
Each run block executes a command against your configuration. Run blocks execute sequentially by default.
Basic Integration Test (Apply Mode - Default):
Unit Test (Plan Mode):
Run Block Attributes:
command- Eitherapply(default) orplanplan_options- Configure plan behavior (see below)variables- Override test-level variable valuesmodule- Reference alternate modules for testingproviders- Customize provider availabilityassert- Validation conditions (multiple allowed)expect_failures- Specify expected validation failuresstate_key- Manage state file isolation (since v1.9.0)parallel- Enable parallel execution when set totrue(since v1.9.0)
Plan Options
The plan_options block configures plan command behavior:
Plan Options Attributes:
mode-normal(default) orrefresh-onlyrefresh- Boolean, defaults totruereplace- List of resource addresses to replacetarget- List of resource addresses to target
Variables Block
Define variables at the test file level (applied to all run blocks) or within individual run blocks.
Important: Variables defined in test files take the highest precedence, overriding environment variables, variables files, or command-line input.
File-Level Variables:
Run Block Variables (Override File-Level):
Variables Referencing Prior Run Blocks:
Assert Block
Assert blocks validate conditions within run blocks. All assertions must pass for the test to succeed.
Syntax:
Resource Attribute Assertions:
Output Validation:
Referencing Prior Run Block Outputs:
Complex Conditions:
Expect Failures Block
Test that certain conditions intentionally fail. The test passes if the specified checkable objects report an issue, and fails if they do not.
Checkable objects include: Input variables, output values, check blocks, and managed resources or data sources.
Testing Custom Conditions:
Module Block
Test a specific module rather than the root configuration.
Supported Module Sources:
- ✅ Local modules:
./modules/vpc,../shared/networking - ✅ Public Terraform Registry:
terraform-aws-modules/vpc/aws - ✅ Private Registry (HCP Terraform):
app.terraform.io/org/module/provider
Unsupported Module Sources:
- ❌ Git repositories:
git::https://github.com/... - ❌ HTTP URLs:
https://example.com/module.zip - ❌ Other remote sources (S3, GCS, etc.)
Module Block Attributes:
source- Module source (local path or registry address)version- Version constraint (only for registry modules)
Testing Local Modules:
Testing Public Registry Modules:
Provider Configuration
Override or configure providers for tests. Since Terraform 1.7.0, provider blocks can reference test variables and prior run block outputs.
Basic Provider Configuration:
Multiple Provider Configurations:
Provider with Test Variables:
State Key Management
The state_key attribute controls which state file a run block uses. By default:
- The main configuration shares a state file across all run blocks
- Each alternate module (referenced via
moduleblock) gets its own state file
Force Run Blocks to Share State:
Parallel Execution
Run blocks execute sequentially by default. Enable parallel execution with parallel = true.
Requirements for Parallel Execution:
- No inter-run output references (run blocks cannot reference outputs from parallel runs)
- Different state files (via different modules or state keys)
- Explicit
parallel = trueattribute
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/hashicorp/agent-skills/terraform-test/SKILL.md
Popularity
- Repository stars
- 66
- Repository forks
- 24
- 7-day trend score
- 26
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
configConfiguration overrides
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/comeonoliver/skillshub/terraform-test)