What Is New in Terraform 1.9
Terraform 1.9 focuses on refining the testing experience and enhancing provider workflows. The headline feature is the general availability of the terraform test command, moving it out of beta with several key improvements.
| Category | Key Changes |
|---|---|
| New Features | General availability of terraform test, Provider-defined functions |
| Enhancements | Test file filtering, Mock providers, Plan output in tests |
| Bug Fixes | Various fixes for the terraform test command and core |
| Deprecations | Removal of previously deprecated features |
What makes the terraform test command production-ready?
The terraform test command has graduated from beta to general availability. This means the command line interface and core functionality are now stable for production use.
You can now write and execute tests in .tftest.hcl files to validate your modules and configurations. The command integrates directly into Terraform's execution workflow, making it a native part of your infrastructure testing strategy.
How can I run specific tests instead of all of them?
Test file filtering allows you to target specific test files during execution. Use the -filter flag with the terraform test command to run only the tests you need.
This is a huge time-saver during development. Instead of running your entire test suite every time, you can focus on the specific .tftest.hcl file you're currently working on.
What are provider-defined functions and why do they matter?
Provider-defined functions enable providers to expose custom functionality directly to Terraform configurations. Providers can now implement and register their own functions alongside built-in ones like lower() or merge().
This opens up powerful possibilities for provider-specific data manipulation and validation. In practice, this means providers can offer domain-specific functions that understand their resources and data sources better than generic Terraform functions could.
Can I test Terraform configurations without real cloud API calls?
Yes, mock providers now let you test Terraform configurations without making actual API calls to cloud platforms. This is implemented through the new testing framework's ability to use mock providers.
You can simulate provider behavior for testing scenarios where you want to verify plan outcomes without creating real infrastructure. This makes tests faster, more reliable, and free from cloud provider dependencies or costs.
What's better about test output and debugging in this release?
The test execution output now includes the plan output for each run block, giving you complete visibility into what changes Terraform would make. This enhancement makes debugging test failures significantly easier.
When a test assertion fails, you can see exactly what the plan looked like at that point in the test. This immediate feedback loop helps you understand why a condition wasn't met without additional debugging steps.
FAQ
Is the terraform test command backward compatible with my existing tests?
Yes, tests written for the beta version should continue to work without changes. The GA release stabilizes the interface without breaking existing functionality.
Can I use provider-defined functions with any Terraform provider?
Only providers that have been updated to implement and expose these functions will support them. Check your provider's documentation for specific function availability.
How do mock providers differ from the existing mock_provider feature?
Mock providers in the test framework are specifically designed for the terraform test command and integrate directly with the testing workflow, providing more control over simulated responses.
Does test file filtering work with directory structures?
Yes, you can use the -filter flag with relative paths to target test files in subdirectories, making it easy to organize tests by component or environment.
Are there any performance improvements in test execution?
While not explicitly called out as a performance release, the addition of test filtering and mock providers significantly reduces test execution time by avoiding unnecessary tests and real API calls.