What problem does it solve?
Ensuring the reliability and correctness of Terraform configurations, especially modules, is challenging. Manual testing is slow and error-prone. This skill provides a comprehensive guide to Terraform's built-in testing framework, enabling you to automate validation, prevent breaking changes, and build robust infrastructure-as-code.
Core Features & Use Cases
- Automated Validation: Write unit and integration tests for your Terraform modules and configurations.
- Mock Providers: Simulate cloud provider behavior for fast, cost-free unit testing without deploying real resources.
- Assertion-Based Checks: Define conditions to validate resource attributes, outputs, and plan changes.
- Use Case: Before deploying a critical VPC module update, use this skill to write tests that verify the new CIDR block, subnet counts, and security group rules, ensuring no regressions are introduced.
Quick Start
I need to write a Terraform test for my AWS VPC module. Guide me on how to create a .tftest.hcl file, define a run block for a plan-mode unit test, and add an assert block to verify the VPC's CIDR block.