Publishing Modules to a Registry
Share reusable Terraform modules across teams by versioning them in Git and publishing to the public or a private module registry.
Publishing Modules to a Registry is a free DevOps Bootcamp lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond Local Modules
Local modules live in a folder next to your config. To share modules across projects and teams you publish them to a module registry so consumers can pull them by name and version, just like a package manager.
Module Sources
The source argument decides where Terraform fetches a module from. Options include:
- A local path
- A Git repository
- The Terraform public registry
- A private registry in Terraform Cloud
Consuming a Registry Module
Registry modules use the format namespace/name/provider. Always pin a version for reproducible builds.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.1.2"
name = "my-vpc"
cidr = "10.0.0.0/16"
}Repository Naming Convention
The public registry requires a specific repo name: terraform-PROVIDER-NAME. For example a network module for AWS would live in a repo named terraform-aws-network.
Standard Module Structure
A publishable module follows a predictable layout so the registry can document it automatically.
terraform-aws-network/
main.tf
variables.tf
outputs.tf
README.md
examples/
basic/main.tfDocumenting Inputs
Each variable should have a description and ideally a type. The registry turns these into a documented inputs table automatically.
variable "cidr" {
type = string
description = "The CIDR block for the VPC"
default = "10.0.0.0/16"
}Versioning with Git Tags
The registry derives module versions from semantic version Git tags. Tagging a release is what makes a new version available to consumers.
git tag v1.0.0
git push origin v1.0.0Pinning a Git Source Directly
You can skip the registry and reference a Git repo by URL, pinning to a tag with the ref query parameter.
module "network" {
source = "git::https://github.com/acme/terraform-aws-network.git?ref=v1.0.0"
cidr = "10.0.0.0/16"
}Private Registries
Terraform Cloud and Enterprise offer a private registry so internal modules stay confidential while still being discoverable by your organization with the same name/version workflow.
Semantic Versioning Constraints
Use version constraints to allow safe upgrades. The ~> operator allows patch and minor bumps but not breaking major changes.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.1"
}Refreshing Module Versions
After changing a version constraint, run terraform init -upgrade to fetch the newest allowed version and update the lock file.
terraform init -upgradeQuick Check
Check your grasp of module versioning.
Recap: Sharing Modules
You learned to publish and consume modules:
- The
terraform-PROVIDER-NAMErepo naming rule. - Standard structure with documented inputs and outputs.
- Git tags drive registry versions.
- Version constraints like
~>keep upgrades safe.
Now your reusable modules can power every project in the org.
Frequently asked questions
Is the “Publishing Modules to a Registry” lesson free?
Yes — the full text of “Publishing Modules to a Registry” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “Publishing Modules to a Registry”?
Share reusable Terraform modules across teams by versioning them in Git and publishing to the public or a private module registry. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Publishing Modules to a Registry” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Terraform Modules
- Creating Reusable Modules
- Using Workspaces for Environments
- Publishing Modules to a Registry