Blog

Terraform module catalog best practices

A catalog is a promise: if you request this, it works and somebody supports it. Most catalogs break that promise in the same handful of ways.

Publish only what you support

A module in a repository is code. A module in a catalog is a commitment. If nobody can answer questions about it, if it has no owner, or if the last change was two years ago, it is not ready to be offered to other teams.

This is the rule people skip first, because publishing is easy and supporting is not. A small catalog with an owner per module beats a large one where every request ends in a question to the same person.

One module, one job

A “networking” module that creates a VPC, subnets, route tables, peering, DNS, and a NAT gateway is hard to review and impossible to reason about when one part changes. Split it. Let the request compose three modules instead of hiding the composition inside one.

The test is simple: can you describe what the module does in one sentence without “and”? If not, it is two modules.

Pin to versions, not branches

A branch moves. A version does not. Every request should record the module version and the commit it was built from, because the honest answer to “what code is running in production” is a version, not a branch name.

Published versions should never change. When a module needs a fix, publish the next version and leave the old one available for environments that already depend on it.

Make the required things required

Defaults are useful for choices where one answer is almost always right: a log retention of 30 days, a private ACL, encryption on. They are dangerous for identity: bucket names, environment names, CIDR ranges.

A useful test: if the default would be wrong in half of the real requests, do not set one. Make the developer decide, with a short explanation of what a good answer looks like.

Validate where the mistake happens

Terraform's validation blocks cost a few lines and catch the errors that otherwise surface as a failed apply: names with uppercase letters, a retention period of zero, a CIDR that overlaps the office network.

The best place to catch those is the request form, not the pipeline. A validation error in a form takes ten seconds to fix. The same error after a plan review takes a day.

Decide which outputs are public

Outputs are how a developer connects this request to the next one: the bucket name, the queue URL, the role ARN. Some outputs should never be visible, such as connection strings or anything derived from a secret.

Treat that as a decision in the catalog entry, not a default. An output marked sensitive should stay out of the request history and out of the API.

Put documentation where the decision happens

One sentence per input, inside the catalog entry, beats a README that nobody opens. “Use this for application logs, not audit logs” prevents more mistakes than a page about module structure.

If your documentation lives only in the repository, developers will not see it at the moment they choose a module and fill in a form.

Test the module, not the cloud

Mocked provider tests catch most regressions: wrong variable wiring, missing resources, broken conditionals. They run in seconds and do not need an account or credentials.

Keep one real end-to-end run for the module that matters most. Everything else can be verified against mocks, as long as the mocks stay current.

Retire on purpose

Catalogs decay because nothing is ever removed. A module that no longer matches how you run infrastructure should stop accepting new requests while existing environments keep working.

Deleting it outright breaks people who followed your advice last year. Closing it to new requests and deleting it when nothing depends on it does not.

Publish fewer modules

Twenty reviewed modules that cover most requests are more useful than two hundred entries nobody has read. The repository can hold everything; the catalog should hold what you are willing to stand behind.

The mechanics of this are covered in the service catalog page. How the request flows is in Terraform self-service, and the review side in guardrails.

Bring a repository and we will tell you which three modules belong in a catalog first.

Book a 30-minute call