terraform test
The command, added in Terraform 1.6, that runs the scenarios in .tftest.hcl files against a module and reports which assertions passed.
In more detail
Each test file holds run blocks that plan or apply the module with chosen variables and check results with assert blocks. Tests that apply create real infrastructure and destroy it afterwards unless providers are mocked. Tests ask whether the module behaves as designed; policy asks whether a change is allowed.
Example
terraform testRelated terms
- .tftest.hcl file — A test file for terraform test, written in HCL, containing run blocks that exercise a module and assert blocks that check the results.
- mock provider — A fake version of a provider, declared with mock_provider in a test file, that returns made-up values instead of calling a real API.
- policy as code — Writing organisational rules, such as required tags or allowed regions, as code that automatically checks every proposed change.
Taught in
- Installing Terraform And Meeting The CLI — Infrastructure as Code with Terraform
- Running Terraform In CI — Infrastructure as Code with Terraform
- Native Testing With Tftest Files — Infrastructure as Code with Terraform
- Provider Mocking For Tests — Infrastructure as Code with Terraform
- Policy As Code With OPA — Infrastructure as Code with Terraform
- Releasing The Real Cloud Artifact — Infrastructure as Code with Terraform
- Custom Conditions: Validation, Pre And Postconditions, Checks — HashiCorp Terraform Associate (004) Exam Prep