hashicorp avatar

Terraform Test

Guide for writing Terraform tests: .tftest.hcl files, run blocks, assertions, mocks, and module output checks.

CCM score
74 of 100
skills.sh installs
9.5K
GitHub stars
941
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers plan and apply test modes, run block syntax, assert and expect_failures usage, sequential run dependencies, and state key sharing
  • Includes reference files for mock providers (Terraform 1.7.0+), GitHub Actions and GitLab CI pipelines, and a full VPC module example suite
  • Enforces a split between *_unit_test.tftest.hcl plan-mode files and *_integration_test.tftest.hcl apply-mode files so CI can filter them separately
  • Designed for module authors writing Terraform tests who need the .tftest.hcl syntax and patterns for output, resource, and data source checks

Install

$ npx -y skills add hashicorp/agent-skills --skill terraform-test -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

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/MOCK_PROVIDERS.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/CI_CD.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

Details

Repository
github.com/hashicorp/agent-skills
Categories
Testing & QA, DevOps & Cloud

More from hashicorp/agent-skills

All 16

Similar to Terraform Test

More Testing & QA