Refactor: Extract formatting utilities to internal/lib#1620
Merged
james00012 merged 3 commits intomainfrom Nov 18, 2025
Merged
Conversation
63ce890 to
3b7d133
Compare
Extract shared formatting functions from modules/terraform to internal/lib/formatting to eliminate dependency from terragrunt to terraform module. Changes: - Create internal/lib/formatting/format.go with extracted functions: - FormatBackendConfigAsArgs() - formats backend config as CLI args - FormatPluginDirAsArgs() - formats plugin directory path - All supporting HCL formatting helpers (toHclString, etc.) - Add comprehensive tests in internal/lib/formatting/format_test.go - Update modules/terraform/format.go to delegate to internal/lib - Update modules/terragrunt/init.go to use internal/lib directly - Remove duplicate tests from modules/terraform/format_test.go Benefits: - Breaks terragrunt -> terraform dependency - Eliminates heavyweight terraform dependencies for terragrunt users - Establishes internal/lib pattern for shared utilities - No breaking changes - all public APIs remain unchanged Impact: - terragrunt no longer imports terraform module - Reduces dependency graph for terragrunt-only users - All tests passing, no functional changes
6744be8 to
f3c8628
Compare
denis256
approved these changes
Nov 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR extracts shared formatting utilities from
modules/terraformto a newinternal/libmodule. This is the first step toward modularizing Terratest while eliminating an unwanted dependency fromterragrunttoterraform.Problem
Currently,
modules/terragruntimportsmodules/terraformjust to use two formatting helper functions:FormatTerraformBackendConfigAsArgs()FormatTerraformPluginDirAsArgs()This creates an unwanted dependency that pulls in heavyweight HCL parsing libraries even for users who only need terragrunt functionality.
Solution
Extract the shared formatting logic to
internal/lib/formatting:terraformandterragruntmodules now use the shared internal libraryChanges
New files:
internal/lib/go.mod- New internal moduleinternal/lib/formatting/args.go- Extracted formatting functionsModified files:
modules/terraform/format.go- Delegates to internal/libmodules/terragrunt/init.go- Uses internal/lib directly (no more terraform import)go.mod- Added replace directive for local developmentTesting
Next Steps
This refactoring prepares the codebase for full modularization (follow-up PR), where we will create independent
go.modfiles for each module to enable users to import only what they need.Related
Addresses the dependency concerns raised in #1392, #1492, and avoids the mistakes from the reverted PR #1608.