Terraform Advanced — Publishing to the Registry
Publish reusable modules to the public or private Terraform Registry.
GitHub Naming Convention
The Terraform Registry requires this exact naming pattern:
terraform-<PROVIDER>-<NAME>
Examples:
terraform-aws-vpc
terraform-aws-eks
terraform-google-network
terraform-azurerm-vnet
Required Repository Structure
terraform-aws-vpc/
├── main.tf # Core resources
├── variables.tf # Input variables
├── outputs.tf # Output values
├── versions.tf # Required providers
├── README.md # Auto-generated docs
├── examples/ # Usage examples
│ └── complete/
│ └── main.tf
└── modules/ # Sub-modules (optional)
└── subnets/
Auto-Generated Documentation
Use terraform-docs to generate README.md:
$ brew install terraform-docs
$ terraform-docs markdown table . > README.md
Output:
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|----------|
| name | VPC name | string | n/a | yes |
| cidr | CIDR block | string | "10.0.0.0/16" | no |
## Outputs
| Name | Description |
|------|-------------|
| vpc_id | The VPC ID |
Publishing Steps
- Push repo to GitHub with
terraform-<provider>-<name>naming - Create a Git tag:
git tag v1.0.0 && git push origin v1.0.0 - Sign in to registry.terraform.io with GitHub
- Click “Publish” → Select your repository
- The registry auto-detects versions from Git tags
What’s Next?
Choose between monorepo and polyrepo for modules.