Test a Module
Set up automated integration and Tofu/Terraform testing pipelines for your Harness IaCM Module Registry modules to catch issues before teams adopt new versions.
Test module changes before teams adopt new versions. Harness Module Registry supports integration testing and native OpenTofu/Terraform testing through automated testing pipelines.
Integration testing provisions real infrastructure and destroys it after the test. OpenTofu/Terraform testing runs native test files against the module.
Before you begin
Registered module: A module registered in the Harness IaCM Module Registry. Go to Register a Module to register a module.
Harness project access: Execute permissions on IaCM pipelines. Go to RBAC in Harness to configure roles.
Cloud provider connector (integration testing only): A connector with credentials to create and destroy real infrastructure. Go to Add an AWS connector to set up a connector.
Choose a testing method
Integration testing validates your module against real infrastructure. Harness runs init → plan → apply → destroy for each example in the module's examples/ directory.
Add integration test cases
To enable integration testing, add an examples/ directory to your module repository. Each subdirectory represents a test case and should contain a valid OpenTofu or Terraform configuration:
module-repository/
├── main.tf
├── variables.tf
├── outputs.tf
├── examples/ # Required for integration testing
│ ├── basic-example/ # Test case 1
│ │ ├── main.tf
│ │ ├── variables.tf # Optional
│ │ └── outputs.tf # Optional
│ └── advanced-example/ # Test case 2
│ ├── main.tf
│ ├── variables.tf # Optional
│ └── outputs.tf # Optional
└── README.mdConfigure the target branch
Module testing uses the target branch configured when you register the module. A pull request targeting that branch triggers the module's configured testing pipelines. Go to Register a Module to set the target branch.
How module testing works
A pull request against the configured branch triggers the testing pipeline through a webhook. The pipeline runs the IACM Module Test step and returns a pass or fail result for the module version.
The testing pipeline receives the module's moduleId as a runtime input through the webhook. In the pipeline YAML, moduleId is defined as <+input>, which makes the pipeline reusable across modules.
Example pipeline YAML
The testing pipeline receives the module ID as a runtime input. In this example, IACM Module Test runs the integration-test command:
Provisioning workspaces are not supported in module testing pipelines. Use the moduleId runtime input to identify the module under test. Adding a provisioning workspace stage causes execution to fail.
Requirements
Integration testing requires a cloud provider connector. Integration tests create and destroy real infrastructure, so the connector provides the credentials required to provision the test resources.
OpenTofu/Terraform testing requires selecting a provisioner and version during setup (for example, OpenTofu 1.9.0). No cloud provider connector is required.
Set up module testing
Set up testing from the Test Executions tab of the module you want to test. The setup wizard is titled Module Registry Testing Setup.
From the IaCM Module Registry, select a module.
Select the Test Executions tab, then click Set up Module testing.
In the Organization and Project step, select an organization and project, then click Next.
In the Testing workspaces step, select a cloud provider connector and your provisioner and version, for example, OpenTofu 1.9.0, then click Next.
In the Testing Pipeline step, select your default pipelines to run against pull requests.
By default, an Integration test (
iacm_auto_generated_integration_testing) and an OpenTofu/Terraform test (iacm_auto_generated_tofu_testing) pipeline are created for you.
Select Finish.
To create a custom module testing pipeline:
Navigate to Pipelines, then click Create.
Add a Testing stage and select Integration Testing or OpenTofu/Terraform Testing.
Use the IACM Module Test step to run tests against the module.
Set
moduleIdas a runtime input (<+input>) so the pipeline can be reused across modules.Do not add provisioning workspace stages. Provisioning workspaces are not supported in module testing pipelines.
Credit usage
Default testing pipelines or custom pipelines using Harness steps
No credits consumed
Custom pipelines using workspaces
Credits consumed
Troubleshooting
Next steps
Go to PR automation to create a PR and see automated testing in action.
Go to Manage Version Lifecycle to manage the lifecycle of tested versions.
Go to Govern Module Usage to apply OPA policies controlling which modules and versions teams can use.
Last updated
Was this helpful?