Test-integrated modules in the Terraform Cloud private registry
You can configure Terraform Cloud to automatically run tests for modules in your private registry. When enabled, Terraform Cloud will run tests for every commit to the designated branch. This lets you verify that it is safe to publish new module versions.
To enable testing when you publish your module:
- Choose the Branch module publishing type
- Assign a branch and a module version
- Under testing, click the Enable testing for module checkbox
- Click Publish module
To enable testing after you publishing your branch-based module:
- Navigate to the module overview screen
- Click Configure Tests to open the Tests Settings screen
- Click Enable testing for module
After publishing and enabling testing for your module, you can use the Terraform CLI locally to trigger remotely-executed tests in Terraform Cloud. This lets you test your module changes using the credentials configured in Terraform Cloud without committing your changes to version control.
To run your tests remotely, use the
-cloud-run flag with the path to your module in your private registry.
terraform test -cloud-run=app.terraform.io/:ORG/:MODULE_NAME/:PROVIDER
You can define test-specific environment variables that Terraform Cloud will use for testing. If your tests provision infrastructure, you must configure provider credentials for the module.
To add environment variables to your module's tests:
- On the module overview screen, click Configure Tests.
- In the Variables section on the Tests Settings screen, click + Add variable.
- Provide a Key and Value for your environment variable, and if you want to protect the variable's value, click the Sensitive checkbox.
- Click Add variable to save it.
Note: Generated module tests are available in Terraform Cloud Plus Edition and are in public beta. Refer to Terraform Cloud pricing for details.
To generate tests for your module:
- On the module overview screen, click Generate tests.
- Click Confirm. It will take a few minutes to generate your module tests.
- Terraform Cloud displays generated configuration. To download all of the test files, click Download generated tests.
- Create a
testsdirectory in your configuration.
- Unzip the downloaded files into the new