A module repository contains main.tf, variables.tf and a tests directory holding network_test.hcl and defaults_test.hcl, each with run and assert blocks. Running terraform test from the module root reports that no tests were found. What is the cause?
Select an answer to reveal the explanation.
Short Explanation
Terraform finds tests by their last name, not their address: the file has to end in .tftest.hcl or .tftest.json. Name a file network_test.hcl and you've made it invisible, no matter which folder it sits in.
Full Explanation
Test discovery in Terraform is driven by file extension. terraform test loads files ending in .tftest.hcl or .tftest.json from the root configuration directory and from the test directory, which defaults to tests. Files named network_test.hcl and defaults_test.hcl have an ordinary .hcl extension, so they are not recognised as tests even though they sit in the right folder; renaming them to network.tftest.hcl and defaults.tftest.hcl fixes discovery. Running from inside tests is the wrong direction: the command is executed from the root configuration directory, just like plan and apply, and paths in test files resolve relative to that directory. There is no registration mechanism in main.tf; the optional test block lives inside a test file and configures behaviour such as parallel execution rather than listing files. The -filter option narrows which discovered test files run; it cannot make a file with the wrong extension visible and it is not required for normal discovery. Exam caveat: -test-directory changes the folder searched, and test files in the root directory are always loaded regardless of that option, so a directory problem and an extension problem present differently. Operational check: rename the files, run terraform test from the module root, and confirm each run block appears in the output with a pass or fail result.