terraform-test

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

1|1|Updated Dec 30, 2025
One-click install
npx skills add https://github.com/anyscale/terraform-provider-anyscale --skill terraform-test-anyscale
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: terraform-test
Source: https://github.com/anyscale/terraform-provider-anyscale/tree/main/.claude/skills/terraform-test
Command: npx skills add https://github.com/anyscale/terraform-provider-anyscale --skill terraform-test-anyscale

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing automated tests for Terraform modules requires knowing the .tftest.hcl syntax, run block semantics, plan versus apply modes, and mock provider configuration, which many practitioners get wrong or skip entirely. ## Core Features & Use Cases - Test File Authoring: Create .tftest.hcl files with run blocks, assert blocks, variables, and expect_failures for validating module behavior. - Unit and Integration Testing: Use command = plan for fast logic validation or command = apply for real infrastructure testing with automatic cleanup in reverse run order. - Mock Providers: Simulate provider behavior without cloud credentials or costs using mock_provider blocks (Terraform 1.7.0+). - Use Case: A module author needs to verify that a VPC module creates the correct subnets and rejects invalid CIDR blocks; this Skill guides writing plan-mode unit tests, apply-mode integration tests, and negative tests with expect_failures. ## Quick Start Write a Terraform test file that validates my VPC module creates two private subnets and rejects an invalid 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 a Terraform test file for my module?▼

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

What is the difference between plan and apply in Terraform tests?▼

command = plan validates logic without creating real infrastructure, making tests fast and free. command = apply (the default) creates real resources for integration testing and destroys them automatically in reverse run block order.

How do I test Terraform without creating real cloud resources?▼

Use command = plan to validate logic only, or add mock_provider blocks (Terraform 1.7.0+) with mock_resource and mock_data defaults to simulate provider behavior without credentials or API calls.

Can Terraform test files use modules from Git repositories?▼

No. Terraform test files only support local module paths and public or private registry modules. Git, HTTP, and other remote sources must be cloned locally or published to a registry first.

How do I test that invalid variable inputs are rejected?▼

Use the expect_failures attribute in a run block listing the checkable objects (such as var.name) that should fail validation. The test passes when those objects report errors as expected.

Why do my Terraform tests interfere with each other?▼

Run blocks sharing a state file can conflict. Use separate modules for automatic state isolation, set distinct state_key attributes, or use mock providers to isolate tests from shared state.