terraform-test

Validate Terraform configurations with repeatable unit and integration tests.

790|117|Updated Nov 8, 2025
One-click install
npx skills add https://github.com/hashicorp/agent-skills --skill terraform-test-hashicorp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terraform-test
Source: https://github.com/hashicorp/agent-skills/tree/main/terraform/code-generation/skills/terraform-test
Command: npx skills add https://github.com/hashicorp/agent-skills --skill terraform-test-hashicorp

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Terraform configurations are frequently changed and require validation to avoid unintended changes. This Skill provides a structured approach to writing and running Terraform tests that catch regressions before deployment.

Core Features & Use Cases

  • Define test files (.tftest.hcl or .tftest.json) to describe scenarios.
  • Use run blocks, variables, provider and module configurations, and mock_provider to simulate infrastructure.
  • Assert outcomes and outputs to verify correctness, behavior, and dependencies.

Quick Start

Create a tests/ directory, add a .tftest.hcl file with at least one run block, and run terraform test to execute your unit or integration tests.

Frequently Asked Questions about terraform-test

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write Terraform tests to validate configurations before deployment?

To write Terraform tests, create a tests/ directory and add a .tftest.hcl or .tftest.json file with at least one run block. You can define variables, assert outputs, and execute tests using the terraform test command to validate plan and apply scenarios.

What is the difference between unit and integration testing in Terraform?

Terraform unit testing validates the plan phase using mock providers to simulate infrastructure without deploying changes. Integration testing executes the apply phase to verify actual infrastructure behavior, ensuring dependencies and outputs function correctly in real scenarios.

How do I use mock_provider to simulate infrastructure in .tftest.hcl files?

Use the mock_provider block within your .tftest.hcl files to simulate infrastructure dependencies and isolate Terraform configurations. This allows you to assert planned outcomes and outputs without provisioning real cloud resources during unit tests.

Can I use run blocks to test modules and assert outputs in Terraform?

Yes, run blocks in .tftest.hcl files execute specific modules or configuration files, allowing you to pass variables and assert outputs. This verifies that module dependencies and infrastructure behave as intended across different testing scenarios.

Does terraform test support both .tftest.hcl and .tftest.json formats?

Yes, the terraform test command supports both .tftest.hcl and .tftest.json file formats. You can define test scenarios, run blocks, variables, and mock providers in either format to validate your infrastructure configurations.

Why are my Terraform configuration tests failing to catch unintended changes?

If tests fail to catch regressions, ensure your .tftest.hcl files include comprehensive assertions for outputs and behaviors. Properly configure run blocks, variables, and mock providers to accurately simulate both plan and apply workflows.