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. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.
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.
Learn DevOps Bootcamp with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 142
- Lessons
- 568
Frequently Asked Questions
Is the “Publishing Modules to a Registry” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Publishing Modules to a Registry”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
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