terraform-test

Write and run Terraform test files with run blocks, assertions, and mock providers.

Updated Jun 13, 2026
One-click install
npx skills add https://github.com/jenreh/project-kit-template --skill terraform-test-jenreh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terraform-test
Source: https://github.com/jenreh/project-kit-template/tree/main/.agents/agent-skills/skills/terraform-test
Command: npx skills add https://github.com/jenreh/project-kit-template --skill terraform-test-jenreh

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing Terraform tests requires knowing the .tftest.hcl syntax, run block structure, assertion patterns, and mock provider configuration, which is easy to get wrong without a reference. This Skill provides the patterns and commands needed to validate infrastructure code before it reaches production. ## Core Features & Use Cases - Test Authoring: Create .tftest.hcl files with run blocks, assertions, variables, plan options, and expect_failures for validation rules. - Mock Providers: Simulate AWS resources and data sources without credentials for fast plan-mode unit tests (Terraform 1.7.0+). - CI/CD Integration: GitHub Actions and GitLab CI pipeline examples that separate unit tests from integration tests. - Use Case: You are building a VPC module and want to verify subnet counts, tag inheritance, and CIDR validation. Use this Skill to generate plan-mode unit tests, mock-based tests, and an apply-mode integration test, then wire them into a pull request pipeline. ## Quick Start Write Terraform unit tests in plan mode with assertions for my VPC module and show me how to run them with terraform test.

Frequently Asked Questions about terraform-test

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

FAQPage Schema
How do I write a Terraform test file?

Create a .tftest.hcl file in a tests/ directory containing at least one run block with a command (plan or apply) and assert blocks with conditions and error messages. Run it with terraform test from the module root.

How to mock AWS providers in Terraform tests?

Use a mock_provider block with mock_resource and mock_data entries defining default attribute values, then run tests with command = plan. Mock providers require Terraform 1.7.0 or later and only work in plan mode.

What is the difference between plan and apply mode in terraform test?

Plan mode validates configuration logic without creating resources, making it fast and credential-free. Apply mode creates real temporary infrastructure to verify actual resource behavior, then destroys it in reverse run block order.

Can Terraform tests use modules from git or HTTP sources?

No. Test files only support local paths and registry modules in the module block. Convert git or HTTP module sources to local modules before referencing them in tests.

Why do my Terraform tests interfere with each other?

Run blocks share state by default within a test file. Use the state_key attribute to isolate or deliberately share state between runs, or split tests into separate modules for full isolation.