Skip to main content

Test Module Versions

warning

Module registry testing is currently pending release and will be available soon!

Modern infrastructure development relies on reusable modules to ensure consistency and scalability. However, without proper testing, modules can create risks such as regression, breaking existing functionality, and introducing security vulnerabilities.

Harness simplifies module testing by automating the process, reducing potential errors, and increasing confidence in your infrastructure code across environments.

Types of testing pipelines

As part of module registry testing, Harness creates two default pipelines per module:

Integration testing verifies your module by:

  • Creating real infrastructure
  • Testing functionality
  • Destroying the infrastructure
example folder

Integration testing iterates and runs tests for each example in the examples/ folder.

File structure

To enable integration testing, include an examples/ folder in your module repository. Each subfolder should contain standard Terraform code (e.g., main.tf, variables.tf, outputs.tf).

module-repository/
├── main.tf # Main module code
├── 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.md

Harness provides an out-of-the-box pipeline for integration testing that will execute the init → plan → apply → destroy commands against your main.tf file in each subfolder. If you require customization, you can amend the pipeline or select your own custom pipeline.


Pipeline configuration

Key aspects of the testing pipelines:

1. Testing stage and steps:

  • Each testing pipeline includes a dedicated testing stage with a single step using the IACM Module Test plugin. The moduleId input is dynamically passed via webhooks, ensuring precise targeting of modules during testing.

2. Default testing pipeline:

  • You can select a default testing pipeline for your module
  • When a PR is created, your default pipeline automatically executes
workspace restrictions

Workspaces are not supported in module testing pipelines and will cause execution to fail. Use the moduleId input instead for module-specific testing.

3. Using the moduleId input:

  • The moduleId is passed automatically as part of the pipeline execution via webhooks set up during the module configuration process.
  • The moduleId is defined in the pipeline as a dynamic input using the <+input> expression. This allows for flexible and reusable pipeline configurations tailored to different modules.

Branch configuration

When defining a module while registering it in the module registry, you configure a target branch. Any PRs created against this configured branch will trigger the associated testing pipelines.

Select a connector

If you choose to use integration testing, you must select a connector. This is necessary because:

  • Integration tests create and destroy real infrastructure
  • The connector provides the necessary credentials and access

Credit Usage

avoid credit consumption

Testing pipelines using Harness-provided plugins (e.g., Integration Testing or Tofu/Terraform Testing) do not consume workspace credits.

However, custom pipelines or the use of regular plugin steps against your workspace will consume credits.

ScenarioCredit Usage
Default testing pipelines or Custom pipelines using Harness stepsNo credits consumed
Custom pipelines using workspacesCredits consumed

Use module testing


Get started today

Ready to improve your module quality and reliability? Follow these next steps:

  1. Set up your repository structure using the examples above.
  2. Configure module testing in your Harness IaCM account
  3. Create a PR to see automated testing in action

By implementing module testing, you'll catch issues earlier, ensure consistent behavior across environments, and build confidence in your infrastructure modules.