feat: add recursive test handling to terraform test
command
The terraform test
command was a nice addition, but many projects don't
keep the root of the terraform module in the root of the repository.
Additionally, projects which contain multiple terraform modules may have multiple tests that need to be run.
This change allows those projects to be supported.
Currently projects that don't declare a module in the root directory fail. For instance: https://gitlab.com/gitlab-com/gl-infra/data/sla-analytics-pipeline/-/jobs/11139345048
How it works
The job automatically discovers directories that contain both:
-
*.tf
files (Terraform configuration) - A
tests/
subdirectory with*.hcl
files (Terraform test files).
For more information on this layout, see the Terraform documentation.
It then runs terraform test
in each of these directories, collecting all test results into separate JUnit XML files for reporting.
If no directories meet these criteria, it falls back to running in the root directory (if it contains *.tf
files).