terraform-test

Write and run Terraform .tftest.hcl tests for Azure infrastructure modules.

Updated May 12, 2026
One-click install
npx skills add https://github.com/sohamda/apex-try-out-demo-repo --skill terraform-test-sohamda
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: terraform-test
Source: https://github.com/sohamda/apex-try-out-demo-repo/tree/main/.github/skills/terraform-test
Command: npx skills add https://github.com/sohamda/apex-try-out-demo-repo --skill terraform-test-sohamda

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Terraform modules for Azure infrastructure often ship without automated validation, so naming errors, missing tags, and broken conditional logic are only discovered during deployment. This Skill provides the patterns and commands to write and run Terraform's built-in test framework (.tftest.hcl) so module behavior is verified before any real resources are created. ## Core Features & Use Cases - Unit and Integration Tests: Write plan-mode unit tests for fast, cost-free validation and apply-mode integration tests that create and destroy real Azure resources. - Mock Providers: Simulate the azurerm provider without API calls or credentials, enabling tests in CI pipelines and local development. - Validation Coverage: Use expect_failures to confirm variable validation rules reject invalid input, and assertions to check naming, tags, and resource counts. - Use Case: You are building an Azure networking module and want to verify that subnets are created correctly, mandatory tags are applied, and invalid environment values are rejected — all before merging a pull request. ## Quick Start Ask the agent to write a plan-mode unit test file for your Terraform module that validates resource naming and mandatory tags, then run terraform test to execute it.

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 for an Azure module?▼

Create a .tftest.hcl file in a tests/ directory with one or more run blocks containing assert conditions. Use command = plan for fast unit tests that validate naming, tags, and logic without creating resources.

How do I test Terraform without Azure credentials?▼

Use mock providers, available since Terraform 1.7, to simulate the azurerm provider without real API calls. Define mock_provider "azurerm" with mock_resource and mock_data blocks that return default attribute values.

What Terraform version is required for the test framework?▼

Test blocks and run blocks require Terraform 1.6 or later. Mock providers require 1.7, and parallel run block execution with state_key management requires Terraform 1.9.

When should I use plan mode versus apply mode in Terraform tests?▼

Use plan mode for unit tests validating logic, naming, and tags since it creates no resources and runs fast. Use apply mode only for integration tests that must verify actual Azure resource creation and API behavior.

Why do Terraform mock providers not work with apply command?▼

Mock providers only support command = plan because they simulate provider responses rather than calling real APIs. For apply-mode integration tests, configure real Azure credentials and let Terraform create and destroy actual resources.

How do I test that Terraform variable validation rejects bad input?▼

Add expect_failures to a run block listing the variables that should fail validation, such as expect_failures = [var.environment]. The test passes only when Terraform rejects the invalid value as expected.