INTRODUCTION:-
We can configure HCP Terraform to automatically run tests for modules present in terraform private registry. When enabled, HCP Terraform will run tests for every commit to the designated branch. This lets you verify that it is safe to publish new module versions.
PROBLEM:-
The tree structure was like this:
module-test
├── modules
│ └── monitor-module
│ ├── locals.tf
│ ├── main.tf
│ ├── outputs.tf
│ ├── README.md
│ ├── variables.tf
│ └── versions.tf
└── tests
└── monitor-module.tftest.hcl
Getting the following error when triggering terraform test from CLI.
$ terraform test -cloud-run=app.terraform.io/hashicorp/platform/module-test Waiting for the tests to start... (0s elapsed) Terraform v1.9.7 on linux_amd64 Error: No Terraform configuration files found in working directory
CAUSE:-
It is because:
1. module directory structure is different from expected one.
2. Execution of terraform test should be for the same directory where terraform configuration exists.
SOLUTION:
- The terraform test command is supposed to be executed at the path where terraform configuration exists ie. module-test/modules/monitor-module.
- We can provide custom test file path using -test-directory=path.
- However it is supposed to be in local vicinity of the configuration path not outside it.
OUTCOME:
We can provide custom test file path using -test-directory=path.However it is supposed to be in local vicinity of the configuration path not outside it.
ADDITIONAL INFORMATION:-
https://developer.hashicorp.com/terraform/cloud-docs/registry/test#run-tests-remotely-from-the-cli
For additional assistance please contact HashiCorp Support.