terraform-test

Write and execute Terraform tests using run blocks and assertions.

Updated Jan 30, 2026
One-click install
npx skills add https://github.com/spallempati/AI-Studio --skill terraform-test-spallempati
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terraform-test
Source: https://github.com/spallempati/AI-Studio/tree/main/skills/terraform/terraform-test
Command: npx skills add https://github.com/spallempati/AI-Studio --skill terraform-test-spallempati

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on writing and executing tests for Terraform configurations, ensuring infrastructure code is robust and reliable.

Core Features & Use Cases

  • Test File Structure: Understand .tftest.hcl and .tftest.json formats.
  • Run Blocks: Define test scenarios with apply or plan commands.
  • Assertions: Validate infrastructure state and outputs.
  • Mock Providers: Simulate provider behavior for isolated testing.
  • Use Case: You're developing a new Terraform module for a VPC. Use this Skill to learn how to write unit tests to validate its configuration and integration tests to ensure it deploys correctly in a real environment.

Quick Start

Use the terraform-test skill to write a unit test for your Terraform module that validates the default instance type.

Frequently Asked Questions about terraform-test

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

FAQPage Schema
How do I write tests for Terraform configurations using the built-in testing framework?

To write Terraform tests, you create `.tftest.hcl` or `.tftest.json` files containing run blocks that execute `apply` or `plan` commands, along with assertions to validate your infrastructure state and outputs.

What are mock providers in Terraform testing and when should I use them?

Mock providers in Terraform testing simulate provider behavior to enable isolated testing of configurations. You use them when you need to validate module logic without deploying real cloud resources or relying on external API endpoints.

How do I validate Terraform module outputs and state with assertions?

You validate Terraform module outputs by defining assertions within your test run blocks. These assertions check the infrastructure state and output values returned by `apply` or `plan` commands to ensure they match expected configurations.

Can I test Terraform modules without deploying to a real environment?

Yes, you can test Terraform modules without real deployments by using mock providers to simulate infrastructure behavior. This allows you to run isolated unit tests validating configuration logic before executing integration tests.

What is the difference between apply and plan run blocks in .tftest.hcl files?

In `.tftest.hcl` files, `plan` run blocks execute a Terraform plan to validate expected changes without modifying state, while `apply` run blocks execute the configuration to provision resources and test the actual resulting infrastructure state.

Why are my Terraform tests failing during CI/CD pipeline execution?

Terraform tests may fail during CI/CD execution due to misconfigured mock providers, incorrect assertion logic against outputs, or invalid run block structures in your `.tftest.hcl` files. Troubleshoot by validating test file syntax and module configurations.