Skip to content

Publishing to the Terraform Registry

This repository is a monorepo of reusable modules. That layout is ideal for Git-based consumption (source = "github.com/rafaelcarvajal05/terraform-stacks//modules/<name>?ref=<tag>") and for the paid Pro distribution, but the public Terraform Registry does not publish from a monorepo: it requires one dedicated GitHub repository per module.

This document is the checklist to get the free modules onto https://registry.terraform.io. Everything here that touches your GitHub account or the Registry is a human step (it is not automated by the agent loop). The module content is already Registry-ready — see "What is already done" at the end.

1. Registry requirements (per module)

The Registry has hard rules. Each module must live in its own public repo that satisfies all of:

Requirement This repo
Repo name is exactly terraform-<PROVIDER>-<NAME> e.g. terraform-aws-vpc
Repo is public on GitHub you create it
Standard module structure at the repo root (main.tf, variables.tf, outputs.tf) ✅ already true inside each modules/<name>/
A README.md with a description and a Usage example ✅ present in every module
At least one semver git tag vX.Y.Z you tag after the split
examples/ directory (optional but shown on the Registry page) available in this repo

Provider namespace: the modules will publish under your Registry namespace (your GitHub org/user, rafaelcarvajal05), as rafaelcarvajal05/<name>/aws.

2. Module → target repo mapping

Monorepo path Target public repo Registry address
modules/vpc terraform-aws-vpc rafaelcarvajal05/vpc/aws
modules/eks terraform-aws-eks rafaelcarvajal05/eks/aws
modules/github-oidc terraform-aws-github-oidc rafaelcarvajal05/github-oidc/aws
modules/ecs-fargate-service terraform-aws-ecs-fargate-service rafaelcarvajal05/ecs-fargate-service/aws

Pro modules (any directory with a .tier file containing pro) are never published here. They stay in the private terraform-stacks-pro repo and are delivered by license.

3. The split (mechanical, repeatable)

git subtree extracts a subfolder with its history into a standalone branch you can push to the new repo. Run from the root of this repo, for each free module:

MODULE=vpc            # repeat for eks, github-oidc, ecs-fargate-service
OWNER=rafaelcarvajal05
REPO=terraform-aws-$MODULE

# 1. Create the empty public repo first (GitHub UI or: gh repo create $OWNER/$REPO --public)

# 2. Split the module folder into a branch carrying only its history
git subtree split --prefix=modules/$MODULE -b split-$MODULE

# 3. Push that branch as main of the new repo
git push https://github.com/$OWNER/$REPO.git split-$MODULE:main

# 4. Tag a release ON THE NEW REPO so the Registry has a version to ingest
git clone https://github.com/$OWNER/$REPO.git /tmp/$REPO
cd /tmp/$REPO && git tag v0.1.0 && git push origin v0.1.0

# 5. Clean up the local split branch
cd - && git branch -D split-$MODULE

The source lines in each module's Usage example currently point at this monorepo via Git. Once a module is on the Registry, its consumers can switch to the Registry short form:

module "vpc" {
  source  = "rafaelcarvajal05/vpc/aws"
  version = "~> 0.1"
  # ...
}

4. Connect to the Registry (one-time, per module)

  1. Sign in to https://registry.terraform.io with GitHub.
  2. Publish → Module, pick terraform-aws-<name>, confirm the provider is aws.
  3. The Registry reads the repo, lists the tags and renders the README + inputs/outputs automatically.
  4. Each new vX.Y.Z tag you push afterwards is ingested within minutes — no re-publish needed.

5. Keeping the repos in sync

The monorepo stays the source of truth. To ship an update to a module already on the Registry, re-run the git subtree split + push for that module, then tag a new vX.Y.Z on its repo. A small scripts/ helper can wrap steps 2–5 of §3 once the repos exist; it is intentionally not added yet because it needs your repos to exist first and must run under your account.

What is already done (by the agent loop, no account needed)

  • Every free module has the standard structure (main.tf / variables.tf / outputs.tf / versions.tf).
  • Every free module README.md has a description + Usage example and auto-generated Requirements / Providers / Inputs / Outputs tables (terraform-docs, regenerated in CI).
  • Each module pins terraform >= 1.6.0 and aws >= 5.0 in versions.tf.
  • Runnable examples/ exist for vpc, eks, github-oidc and ecs-fargate-service.
  • release-please manages versioning; v0.1.0 is tagged on the monorepo.

What needs you (human steps)

  • Create the four public terraform-aws-* repos under your account (§2).
  • Run the split + tag (§3) — mechanical, ~5 min per module.
  • Connect each to the Registry (§4).
  • Decide whether to switch the Usage source lines to the Registry short form after publishing.

Tracked in issue #26 (needs-human).