terraform-test

Write and validate Terraform test configurations with run and assert blocks.

2|3|Updated Oct 19, 2025
One-click install
npx skills add https://github.com/panchal-ravi/ai-iac-consumer-template --skill terraform-test
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terraform-test
Source: https://github.com/panchal-ravi/ai-iac-consumer-template/tree/main/.claude/skills/terraform-test
Command: npx skills add https://github.com/panchal-ravi/ai-iac-consumer-template --skill terraform-test

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Ensuring the reliability and correctness of Terraform configurations, especially modules, is challenging. Manual testing is slow and error-prone. This skill provides a comprehensive guide to Terraform's built-in testing framework, enabling you to automate validation, prevent breaking changes, and build robust infrastructure-as-code.

Core Features & Use Cases

  • Automated Validation: Write unit and integration tests for your Terraform modules and configurations.
  • Mock Providers: Simulate cloud provider behavior for fast, cost-free unit testing without deploying real resources.
  • Assertion-Based Checks: Define conditions to validate resource attributes, outputs, and plan changes.
  • Use Case: Before deploying a critical VPC module update, use this skill to write tests that verify the new CIDR block, subnet counts, and security group rules, ensuring no regressions are introduced.

Quick Start

I need to write a Terraform test for my AWS VPC module. Guide me on how to create a .tftest.hcl file, define a run block for a plan-mode unit test, and add an assert block to verify the VPC's CIDR block.

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 my infrastructure configurations?

Terraform testing uses .tftest.hcl or .tftest.json files with run blocks for unit tests (plan mode) and integration tests (apply mode), plus assert blocks to validate resource attributes and outputs. This catches configuration errors and regressions before deployment.

Can I test Terraform modules without deploying real cloud resources?

Yes, mock providers in Terraform tests simulate cloud behavior for fast, cost-free unit testing. Mock providers let you verify module logic and resource attributes in plan mode without provisioning actual infrastructure.

What's the best way to structure assertions in a Terraform test file?

Assert blocks define conditions to verify resource attributes, plan changes, and outputs. Combine multiple assertions within a run block to validate expected behavior—such as subnet counts, CIDR blocks, or security group rules—against your infrastructure code.

How do I set up variables and test scenarios in Terraform tests?

Use variables, providers, and run blocks to construct test scenarios. Define variable values at test time, configure mock or real providers per scenario, and execute run blocks sequentially or in parallel to test different configuration paths and edge cases.

Can I integrate Terraform tests into a CI pipeline?

Terraform testing framework integrates into CI/CD systems via test commands and parallel execution. Run tests in your pipeline to catch breaking changes early and ensure infrastructure reliability on every commit.

What happens when a Terraform test reaches cleanup and resource destruction?

Test cleanup follows a defined destruction order: resources created during apply are destroyed in reverse dependency order. Control cleanup behavior with test configuration to ensure proper teardown and prevent resource leaks between test runs.