Terraform · 6 min read
How to structure a reusable Terraform module
A good Terraform module solves one clear infrastructure problem and gives its users a small, predictable interface.
Start with four core files
main.tf— resources and data sourcesvariables.tf— configurable inputsoutputs.tf— values consumers needREADME.md— purpose, requirements and examples
Keep the interface intentional
Expose values that genuinely differ between environments. Avoid turning every resource argument into a variable. Useful defaults make a module easier to adopt while validation catches mistakes early.
Version your module
Use tagged releases and pin module versions in consuming projects. This lets teams upgrade deliberately instead of receiving unexpected changes.
This starter article can be expanded with your own production examples and code.