Back to Skills

terraform-test

Comprehensive guide for writing and running Terraform tests. Use when creating test files (.tftest.hcl), writing test scenarios with run blocks, validating infrastructure behavior with assertions, mocking providers and data sources, testing module outputs and resource configurations, or troubleshooting Terraform test syntax and execution.

622stars74forksUpdated 5/16/2026

Security Assessment

Medium Risk(60/100)

Detected risks:

Secret Exposure([references/CI_CD.md] AWS_ACCESS_KEY)
Sensitive File Access([SKILL.md] .env)
Security Score60/100

About terraform-test

The terraform-test skill is designed to provide a comprehensive framework for testing Terraform configurations, ensuring that infrastructure changes do not introduce breaking behavior. It allows users to write test files in `.tftest.hcl` or `.tftest.json` formats, define run blocks for individual test scenarios, and validate infrastructure behavior with assertions. By using temporary resources for tests, this skill protects existing infrastructure and state files from unintended modifications, making it safe to experiment and verify configurations in isolation.

Key features include the ability to define assertions that must hold true for tests to pass, mock providers to simulate infrastructure behavior without provisioning real resources, and test modes such as `apply` for real resource creation or `plan` for logic-only validation. Users can also control state isolation, override file-level variables, and reference specific modules. Additional capabilities include plan options to manage refresh, replacement, or targeted execution of resources, as well as support for parallel execution and expected failure conditions to handle known test exceptions.

This skill is particularly useful for DevOps engineers, Terraform developers, and infrastructure teams who want to ensure their modules, resources, and configurations work as expected before deployment. Common use cases include validating module outputs, checking conditional resource creation, testing different instance types or regions, integrating tests into CI/CD pipelines, and creating robust unit and integration test suites for both local and registry modules. It is aimed at users seeking reliable automated testing to improve confidence in infrastructure changes and maintain stability across environments.

FAQ

What types of test files can I create with terraform-test?

You can create test files with `.tftest.hcl` or `.tftest.json` extensions, containing run blocks that define individual test scenarios.

Can I mock providers with this skill?

Yes, mock providers are supported to simulate provider behavior without creating real resources, but this requires Terraform version 1.7.0 or higher.

What test modes are available?

Terraform-test supports `apply` mode, which creates real resources, and `plan` mode, which validates logic without provisioning resources.

How can I integrate terraform-test with CI/CD pipelines?

The skill references CI/CD guides that provide examples for GitHub Actions and GitLab pipelines, enabling test automation within your continuous deployment workflow.

Are there any requirements for module sources?

Modules referenced in run blocks must be local paths or registry modules; git or HTTP sources are not supported for testing.

All Files

4 files
references/EXAMPLES.md6.5 KB
View
SKILL.md10.9 KB
View
references/CI_CD.md1.9 KB
View
references/MOCK_PROVIDERS.md4.4 KB
View

Install terraform-test

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill