Best Practices
Terraform module best practices for multi-environment setups
Good modules make dev, staging and production look the same apart from size. These are the rules we follow, and they apply equally to multi-cloud Terraform modules for AWS, Azure and Google Cloud.
One folder per environment, one set of modules
Each environment calls the same reusable modules with its own variables. No copy-pasted code.
Version every module
Environments pin a tag, so a module update reaches staging first and production only when you're ready.
Keep modules small
A module should do one job. Huge modules are hard to test and slow to plan.
Choose workspaces carefully
Workspaces suit identical copies, like per-developer sandboxes. For real environments, separate folders and state are clearer.
Test before release
We use terraform test or Terratest to check modules create what they promise.
Same inputs across clouds
Where it makes sense, AWS, Azure and GCP modules share variable names, so switching provider feels familiar.