Module Registry

env0 Module Registry

The env0 Module Registry is a private registry for Terraform modules, allowing you to privately share and reuse Terraform modules within your organization.

Your organization’s module registry is available through the Organization Menu (in the bottom-left of the screen).

registry menu

Then choose the modules tab

modules tab

Adding a module to the registry

In order to add a module to your registry, enter the Module Registry screen and click on “Create New Module” in the top right. Only organization administrators are permitted to create new modules.

In the first step, you must enter the general details of your module.

  • A Name for your module - This can be any string of your choice.
  • The Provider the module belongs to - This can also be any string of your choice.

These two choices will affect how your module is used (see Using a module in your code). The combination of name and provider must be unique within your organization’s modules.

The Description will be shown to members of your team when they browse the module registry, and is a useful way of summarizing what the module does and when it should be used.

In the second step, you must connect to the VCS provider, where your module’s source code is stored.

Click on the VCS provider you’d like to use, and after you’ve authorized env0 to access your repositories, select a repository from the dropdown and enter the folder where module files are stored (Defaults to root folder).

That’s it! Click “Create” to save your work and create the new module.

Module versioning

In order to use a module, it must be versioned using a semver format (e.g. 1.0.0). The versions must be applied to your source repository as git tags.

Versioning modules for mono-repo

When using a mono-repo for managing several modules, a team might come across the need to tag and manage versions for each module individually.

In order to do that, you have to assign a tag prefix to identify a specific module's version, in env0

For example, to tag a module named module1, we may assign the prefix m1.
When we'd use the tags m1/1.0.0, m1/1.2.4, the versions for the module in env0 will be 1.0.0 and 1.2.4

The delimiter is a /, it shouldn't be part of the written prefix.

📘

Terraform restrictions on tags

Terraform enforces using a valid semver string as a version. Tagging with a prefix won't allow using the tag directly, only the semver part, when using a module from env0's private registry, that is configured to use the tag prefix.

Using a module in your code

In order to use a module from the env0 Module Registry in your Terraform code, you must reference it like this:

module "my-module" {
  source = "api.env0.com/{organization-id}/{module-name}/{module-provider}"
  version = "1.0.0"
}

You can find this exact snippet, pre-filled with your values, in the Instructions tab of your module page.

Using a module locally (or from a different env0 Organization)

When you deploy your Terraform code through env0, login to the env0 Module Registry is handled for you. If you’d like to run the same code locally, in a CI environment, or in a different env0 Organization, you will need to supply the authentication details to Terraform. follow the guide on how to authorize when using a private registry for more info.

The Modules List

The Modules List page is available to every user in the organization by clicking on “Module Registry” in the organization’s menu (bottom left of the screen).

On this page you can see which modules have been set up for your organization. You can use the search box to locate specific modules by name, provider, description, or the users who created them.

The Module Page

The Module By clicking on a module from the Modules List, you will get to the Module page.

On this page you can see the details of your Module.

The Versions dropdown at the top right allows you to switch between the different versions of your module. Versions are linked to Git tags in your repository, which match the semantic versioning schema.

The Readme tab will show the contents of the README.md in your repository.

The Instructions tab will include instructions on how the module can be used in your Terraform code.

Submodules

Rather than creating a dedicated repository for each module, you can create a single repository and place submodules within this larger repository. Using the submodules in code is achieved in the same way as referencing submodules within Git, by using the double slash; "//" and then folder location.

module "my-module" {
  source = "api.env0.com/{organization-id}/{module-name}/{module-provider}//submodule"
  version = "1.0.0"
}

Finding My Module ID

Sometimes you may need your module id for using it in our terraform provider or for some API calls.

You can find it in the module card in the Modules tab under the Registry page.

:pencil2: Suggested Blog Content

Terraform Modules Guide

Terraform Plan Examples

Managing Terraform Variable Hierarchy

Manage Terraform Remote State with a Remote Backend