Publishing Modules to Terraform Registry
What you'll learn: How to share your Terraform modules with teams or the community by publishing them to the Terraform Registry.
What Is Module Publishing?
Once you've created a reusable Terraform module, you can share it beyond your local filesystem by publishing it to the Terraform Registry. This registry acts like a library catalog where teams can discover, version, and consume standardized infrastructure patterns. There are two types:
- Public Registry (registry.terraform.io): Open to the community, like publishing an open-source package
- Private Registry (Terraform Cloud/Enterprise): For organization-internal modules that shouldn't be public
How Publishing Works
Publishing to the public registry requires:
- GitHub repository hosting your module code
- Semantic versioning via Git tags (e.g.,
v1.0.0) - Standard module structure with proper variable definitions, outputs, and a README
- Signing in to the Terraform Registry with your GitHub account and authorizing access to your repository
Once published, users reference your module by its registry namespace:
module "example" {
source = "your-org/module-name/aws"
version = "1.0.0"
# module inputs...
}
The registry automatically pulls versions from your Git tags, making updates seamless.
Why This Matters
Publishing modules promotes reusability and consistency across teams. Instead of copying code between projects, everyone pulls from a single, versioned source. It's like maintaining a shared recipe book instead of rewriting recipes each time you cook.
Key Takeaway: Publishing modules to the Terraform Registry enables version-controlled, discoverable infrastructure patterns that teams can consume using simple source references, promoting standardization and reducing duplication.