terraform-test

Validate Terraform configurations with automated unit and integration tests.

Updated Dec 4, 2025
One-click install
npx skills add https://github.com/CloudbrokerAz/ai-iac-consumer --skill terraform-test-cloudbrokeraz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terraform-test
Source: https://github.com/CloudbrokerAz/ai-iac-consumer/tree/main/.claude/skills/terraform-test
Command: npx skills add https://github.com/CloudbrokerAz/ai-iac-consumer --skill terraform-test-cloudbrokeraz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solves?

This Skill provides a comprehensive guide to Terraform's native testing framework, enabling module authors to validate configuration updates and prevent breaking changes. It helps users write effective unit and integration tests, ensuring infrastructure reliability and reducing deployment risks.

Core Features & Use Cases

  • Test File Creation: Guidance on creating .tftest.hcl files with test, run, and assert blocks for various testing scenarios.
  • Unit & Integration Testing: Differentiates between plan mode (fast, no resources created) for unit tests and apply mode (real infrastructure validation) for integration tests.
  • Mock Providers: Explains how to simulate provider behavior for isolated, cost-free unit tests, accelerating feedback loops (requires Terraform 1.7.0+).
  • Use Case: Develop a robust test suite for a new AWS VPC module, including unit tests for variable validation and output correctness, and integration tests to verify actual VPC creation and subnet configuration.

Quick Start

Explain how to write a unit test for a Terraform module that validates the vpc_id output is not empty and starts with 'vpc-', using command = plan.

Frequently Asked Questions about terraform-test

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

FAQPage Schema
How do I validate Terraform modules with automated tests?

Validate Terraform modules by creating `.tftest.hcl` files with `test`, `run`, and `assert` blocks to execute unit and integration tests. Unit tests use `plan` mode to validate configuration without creating resources; integration tests use `apply` mode to verify actual infrastructure behavior. This catches configuration errors and prevents breaking changes before deployment.

What's the difference between plan and apply modes in Terraform testing?

Plan mode executes unit tests that validate configuration logic and outputs without provisioning actual infrastructure, enabling fast feedback loops. Apply mode runs integration tests that create real resources to verify end-to-end behavior. Choose plan mode for rapid unit testing and apply mode for validating infrastructure reliability.

Can I use mock providers to test Terraform modules without creating resources?

Mock providers simulate provider behavior for isolated, cost-free unit tests when using Terraform 1.7.0 or later. They accelerate feedback loops by allowing configuration validation without provisioning actual infrastructure, reducing testing time and expenses while maintaining test coverage.

How do I handle variable scoping and precedence in Terraform tests?

Terraform tests support variable scoping within `run` blocks and respect variable precedence rules defined in `.tftest.hcl` files. Manage test inputs by setting variables at the test block level, ensuring each test case receives correct configuration and validating module behavior across different input scenarios.

What are the limitations when sourcing modules in Terraform tests?

Module sourcing in Terraform tests has constraints around registry modules and local module paths. Local modules work directly; registry modules may require specific handling. Check module source compatibility and test structure requirements to avoid sourcing errors during test execution.

How do I set up cleanup and destruction behavior in Terraform tests?

Configure cleanup and destruction behavior by defining test block lifecycle rules that control resource teardown after each test runs. This ensures tests remain isolated and prevents resource drift, enabling reliable test reruns and maintaining infrastructure consistency across test suites.