Add independent Go modules for terragrunt and dependencies#1608
Add independent Go modules for terragrunt and dependencies#1608james00012 merged 9 commits intomainfrom
Conversation
5782432 to
5133a02
Compare
Set up Go workspace with go.work and individual module files for better dependency management.
3042e64 to
2690ead
Compare
Create independent formatting functions in terragrunt module to remove dependency on terraform module. This significantly reduces dependencies for users who only need terragrunt testing. Changes: - Add modules/terragrunt/format.go with formatting utilities - Update init.go to use local formatting functions - Remove terraform from terragrunt/go.mod dependencies - Update workspace dependencies Benefits: - Users importing terragrunt no longer pull in HCL parsing libraries - Reduced dependency bloat (no hashicorp/hcl, terraform-json, go-getter) - Easier to update terragrunt independently from terraform
Create a shared formatting module to eliminate code duplication and decouple terragrunt from terraform module dependencies. Changes: - Add modules/formatting module with HCL formatting utilities - Update terraform module to use shared formatting functions - Update terragrunt module to use shared formatting instead of terraform - Remove duplicated format.go from terragrunt module - Add comprehensive tests for formatting module - Update go.work to include formatting module - Update go.mod files with proper dependencies Benefits: - Terragrunt no longer depends on terraform module - Eliminates code duplication (161 lines removed from terragrunt) - Removes heavyweight dependencies from terragrunt: - hashicorp/hcl/v2 - hashicorp/terraform-json - hashicorp/go-getter - tmccombs/hcl2json - zclconf/go-cty - Maintains backward compatibility (all tests pass) - Easier maintenance with single source of truth for formatting
Improve code clarity and maintainability: Changes: - Update comments in formatting module to reflect it's shared by both Terraform and Terragrunt (not Terraform-specific) - Clarify comment in terragrunt/init.go about arguments being passed through to underlying terraform command - Remove unnecessary replace directives from files/go.mod (logger and testing are not imported by this module) All tests passing: - formatting module tests: ✓ - terragrunt init tests: ✓ - builds successful: ✓
Fix CI build failure by reverting dependency upgrades that were accidentally included in the modularization PR. This keeps the PR focused solely on module structure changes. Changes: - Revert gruntwork-io/go-commons from v0.17.2 to v0.8.0 - Remove urfave/cli/v2 (keep v1.22.16) - Downgrade dependencies in all module go.mod files - Clean up indirect dependencies The dependency upgrades introduced breaking API changes in cmd/terratest_log_parser that should be addressed in a separate PR. Fixes CI build errors in PR #1608
yhakbar
left a comment
There was a problem hiding this comment.
LGTM.
I believe this will be a breaking change, right? We might want to call that out in release notes.
Also, we might want to be a bit more mindful with internal/exported packages in these modules. Should all of this be exposed to library consumers? Do we want to make any signature change in any of them a breaking change in the library?
|
Looks like $ go mod tidy
$ git status
On branch workspace-setup
Your branch is up to date with 'origin/workspace-setup'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: go.sum
$ git diff
diff --git a/go.sum b/go.sum
index e4372e14..082f8551 100644
--- a/go.sum
+++ b/go.sum
@@ -166,6 +166,7 @@ github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro=
github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
+github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
This is actually not a breaking change, the public API of modules/terraform and modules/terragrunt remains unchanged (same function signatures and behavior), and consumers still use the same import paths. Only the internal implementation was refactored by moving the private formatTerraformArgs function to a shared module. This change is backward compatible while providing additional flexibility, consumers can now import just the terragrunt module without pulling in the terraform module as a dependency. Regarding internal vs. exported packages - that's a great point about modules/formatting now being public. I think it makes sense to address whether it should be internal/formatting in a follow-up PR to keep this one focused on the core modularization. |
Updates go.sum with missing checksums for various dependencies' .mod files.
denis256
left a comment
There was a problem hiding this comment.
I think it should be released as a breaking change. We may also need to update documentation to reflect new imports.
|
Hey @james00012, Following this PR, we are having issues with our test suites.
according to your comment above, this should be a noop but appears to be breaking things. we import: "github.com/gruntwork-io/terratest/modules/helm"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/retry"
"github.com/gruntwork-io/terratest/modules/terraform" |
|
Breaking things on our end as well.. Bug #1613 describes issue. |
Remove modules/terraform/go.mod and go.sum which were introduced in PR #1608. These files should not exist in the pre-modularization state.
This reverts PR #1608, which introduced independent Go modules for the terragrunt dependency chain. Reverting back to the original monolithic module structure.
This reverts PR #1608, which introduced independent Go modules for the terragrunt dependency chain. Reverting back to the original monolithic module structure.
Revert PR #1608: Revert modularization changes
Summary
Modularizes Terratest by creating independent Go modules for the terragrunt dependency chain. Users can now import only what they need, reducing dependency bloat and CVE vulnerabilities.
Problem
Currently, importing terratest pulls in ALL dependencies (AWS, Azure, GCP, K8s, etc.), causing:
Solution
Created independent modules with their own
go.modfiles:Key achievement: Decoupled terragrunt from terraform module by creating a shared
formattingmodule for HCL functions.Impact
Users importing
modules/terragruntno longer get:Test Plan
Fixes #1392