What I can recommend is to treat your modules for what they are: Public library functions. Meaning common sense advice for those applies:
- Approach writing modules by actually designing an API for it. Don't treat it as a folder to dump resources in.
- Make your API as small as you can get away with.
- Its variables and outputs should be, whenever possible, describe a generic black box that could have its internals swapped.
- Make modules composable where you can. Being able to pass around entire module instances in variables because they have clean, stable APIs is very nice.
- Accept some things will inevitably leak but put in the effort to minimize them.
This blog post and the book from the authors (Terraform Up & Running) has some good ideas that got me started with the basics, but there's not much written with regards to more involved usecases: https://blog.gruntwork.io/how-to-create-reusable-infrastruct...
Also to be fair, with good enough module abstractions and generic enough problems you can completely replace their implementation with few changes to their call sites for things like:
- A module that fully sets up a static site with DNS, CDN on an S3-compatible service
- A module for setting up an OCI image repo, and spinning resources that runs an image from it as a daemon somewhere.
- A module for setting up an OCI image repo, and sets up a "cron" job to run a binary off of it.
Sure the migration is unlikely to be as clean as terra[grunt|form] down && terra[grunt|form] up but it can get close.