Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.4k
Modularize Terratest into 27 independent modules#1632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
01569bf to387d9caCompared21d2f6 to8870a1aCompareThis PR restructures Terratest from a monolithic module into 27 independentGo modules, enabling users to import only the specific functionality they need.Key changes:- Create separate go.mod files for each module in modules/- Add go.work workspace file to coordinate local development- Update CI to build and test modules in workspace mode- Add GitHub Action workflow for auto-tagging module releases- Fix Azure module dependencies and import compatibilityBenefits:- Reduced dependency footprint for users importing specific modules- Independent versioning capability for each module- Faster builds when only specific modules are needed- Better separation of concerns
8870a1a to7c213f5Compare- Update internal module dependencies to v1.0.0- Simplify MIGRATION.md- Add GH_TOKEN docs to release workflow- Expand consumer test coverage- Remove unused replace directives
ThisGuyCodes left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I consider this command:
go get github.com/gruntwork-io/terratest
as part of the API. Causing this command to break existing users will cause a ton of friction and frustration. We should lean into ecosystem conventions here and version the module import path.
It may seem like we need to make a new directory + copy everything, keeping both in the repo, but the only reasonthis is recommended is to support non-module-aware go tooling (the post linked is from 2019); afaik we have no intention of supporting non-module-aware tooling as all of that is way out of official support at this point.
First we need to decide if we're going to version each module independently (in which case we also need to be really careful about never letting module A return non-interface types from module B), or version all of Terratest together (this is what I would advocate for).
Then we place a major version number in the module directive in eachgo.mod file. Typically this is placed at the end:
module github.com/gruntwork-io/terratest/modules/aws/v1the barego get command (without the version suffix) will continue to pull the latestv0.x.x tag, allowing us to even branch + release bug fixes for old versions. And so long as we tag the/v1 suffixed modules withv1.x.x thengo get github.com/gruntwork-io/terratest/modules/aws/v1 will continue to work when we release a/v2 etc.
| if [[ "${{ github.event_name }}" == "release" ]]; then | ||
| # Extract version from release tag (remove 'v' prefix if present) | ||
| VERSION="${{ github.event.release.tag_name }}" | ||
| VERSION="${VERSION#v}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
we have control over this input; validation is great to ensure consistency, but I'd argue we should avoid "auto fixing" incorrect inputs.
If we don't want the v, then we shouldn't put the v in the release name, instead of auto-stripping it.
| go 1.24.0 | ||
| replace ( | ||
| github.com/gruntwork-io/terratest/modules/aws => ../../modules/aws |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this can create a weird situation when we start thinking about future breaking changes.
If we treat the whole of terratest as having one "version", then this is fine. If we want to version each module individually, then this can easily create situations wherepick-instance-type/v2 usesaws/v3 but the customer is usingaws/v2, and thus types will be incompatible.
In fact since replace directives only affect the main go.mod file (not things which import it), this may not even be doing what you think it is. Thego.work file does this for local development.
| **Before:** | ||
| ```bash | ||
| go get github.com/gruntwork-io/terratest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I feel strongly that this command needs to continue to work for existing users.
The accepted way to do breaking changes is to add a version suffix to the import path. You don't have to do this with a new directory, you can just change the module declaration ingo.mod:
module github.com/gruntwork-io/terratest/v1And make sure you tag appropriately.
Go tooling will allow the non-suffix'dgo get command to continue to work, by pulling the latestv0.x.x tag. New users (or folks who want to upgrade) would run:
go get github.com/gruntwork-io/terratest/v1
And they'll get the latestv1.x.x version that's tagged.
This is where we need to decide if we're versioning each module individually (in which case we also need to bereally careful about never letting module A return non-interface types from module B), or version all of Terratest together (this is what I would advocate for).
Uh oh!
There was an error while loading.Please reload this page.
Summary
This PR modularizes Terratest into 27 independent Go modules, enabling users to import only the modules they need without pulling in unnecessary dependencies.
Changes:
modules/go.modwith explicit dependenciesgo.workfor workspace-based developmentgo mod tidywithgo work synccmd/pick-instance-type,cmd/terratest_log_parser):go-commons/entrypointdependency in favor of directurfave/cli/v2go-commons/loggingwith directlogrususageresourcegroup.goimport to useprofiles/latestfor compatibilityMIGRATION.mdwith upgrade instructionsModules:
Breaking Changes:
go.modremoved - users must import specific submodulesMIGRATION.mdfor upgrade instructionsTest plan