0
0
Terraformcloud~5 mins

Module registry for organization in Terraform - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you build infrastructure with Terraform, you often reuse code called modules. A module registry for your organization helps you share and manage these modules easily in one place.
When you want to share Terraform modules with your team without sending files manually.
When you want to keep your infrastructure code organized and reusable across projects.
When you want to control versions of your modules to avoid breaking changes.
When you want to discover and use modules created by your coworkers quickly.
When you want to publish modules securely within your company without exposing them publicly.
Config File - main.tf
main.tf
terraform {
  required_version = ">= 1.3.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 4.0"
    }
  }
  
  cloud {
    organization = "example-org"
  }
}

module "vpc" {
  source  = "app.terraform.io/example-org/vpc/aws"
  version = "1.0.0"

  cidr_block = "10.0.0.0/16"
}

provider "aws" {
  region = "us-east-1"
}

The terraform block sets the Terraform version and provider requirements.

The cloud block specifies your organization name to connect to the private module registry.

The module block uses a module from your organization's registry with a specific version.

The provider block configures AWS region for resources.

Commands
This command logs you into Terraform Cloud to authenticate and access your organization's private module registry.
Terminal
terraform login
Expected OutputExpected
Token saved to configuration file. You are now logged in.
This command initializes your Terraform working directory, downloads the module from your organization's registry, and sets up providers.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding hashicorp/aws versions matching ">= 4.0"... - Installing hashicorp/aws v4.50.0... - Installed hashicorp/aws v4.50.0 (signed by HashiCorp) Initializing modules... - vpc in .terraform/modules/vpc Terraform has been successfully initialized!
This command applies the Terraform configuration, creating or updating infrastructure using the module from your organization's registry.
Terminal
terraform apply -auto-approve
Expected OutputExpected
module.vpc.aws_vpc.main: Creating... module.vpc.aws_vpc.main: Creation complete after 10s [id=vpc-0abcd1234efgh5678] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-auto-approve - Automatically approve the plan without asking for confirmation
This command shows the Terraform version and confirms that the setup is using the correct version compatible with the module registry.
Terminal
terraform version
Expected OutputExpected
Terraform v1.3.9 on linux_amd64 + provider registry.terraform.io/hashicorp/aws v4.50.0
Key Concept

If you remember nothing else from this pattern, remember: the module registry lets your team share and reuse Terraform modules easily and safely inside your organization.

Common Mistakes
Not running 'terraform login' before using modules from the private registry
Terraform cannot authenticate to download modules from your organization's registry, causing errors.
Always run 'terraform login' once to authenticate before running 'terraform init' or 'terraform apply'.
Using incorrect module source address without the organization prefix
Terraform cannot find the module because the source path is incomplete or wrong.
Use the full source address including your organization name, like 'app.terraform.io/example-org/module-name/provider'.
Not specifying module version, leading to unexpected module updates
Terraform may use the latest module version, which could introduce breaking changes.
Always specify the module version explicitly in the module block to control updates.
Summary
Run 'terraform login' to authenticate with your organization's Terraform Cloud registry.
Use the full module source address with your organization name in your Terraform configuration.
Run 'terraform init' to download modules and providers, then 'terraform apply' to create infrastructure.