Skip to content

Conversation

@james00012
Copy link
Contributor

@james00012 james00012 commented Dec 1, 2025

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:

  • Split monolithic module into 27 independent modules under modules/
  • Each module has its own go.mod with explicit dependencies
  • Added go.work for workspace-based development
  • Updated CI configuration for modular structure:
    • Pinned goimports to v0.21.0 (avoids Go 1.24.0 requirement)
    • Replaced go mod tidy with go work sync
  • Fixed missing dependencies across all modules

Modules:

  • Tier 0 (no deps): collections, testing
  • Tier 1 (minimal deps): logger, random, retry, shell, files, environment, git
  • Tier 2: ssh, http-helper, dns-helper, oci, opa, packer, docker, database, slack
  • Tier 3: terraform, terragrunt, aws, azure, gcp, k8s, helm, test-structure, version-checker

Known Issues:

  • Azure module has a code issue with deprecated SDK package (services/preview/sql/mgmt/v3.0/sql) that needs separate fix

Test plan

  • CircleCI passes all tests
  • Verify modules can be imported independently
  • Test consumer simulation passes

@james00012 james00012 force-pushed the feature/complete-modularization branch from 01569bf to 387d9ca Compare December 1, 2025 15:41
Implements complete modularization with no root go.mod, eliminating
dependency bloat and fixing ambiguous import errors.

Fixes #1613

- Remove root go.mod
- Add go.work workspace for local development
- Create go.mod for each of 27 modules + internal/lib
- Comprehensive test suite in test/modularization/
- Documentation in MODULARIZATION.md

**Before:** Importing any module pulls entire ~50MB library with all cloud SDKs

**After:** Import only what you need (~5MB for terraform module)

- **No ambiguous imports** - Each package has exactly one source
- **Reduced dependencies** - Import only needed modules
- **Independent versioning** - Each module versions separately
- **Cleaner dependency graphs** - No hidden transitive deps from root

```go
import "github.com/gruntwork-io/terratest/modules/terraform"
```

```go
require github.com/gruntwork-io/terratest/modules/terraform v0.1.0
```

No replace directives needed - Go fetches from GitHub tags automatically.

```bash
cd test/modularization
go test -v ./...
```

Tests validate:
- Dependency isolation
- No ambiguous imports
- All modules build independently
- Workspace builds successfully

No breaking changes - import paths stay the same. Consumers automatically
pull only needed modules instead of everything.
When a GitHub release is published, this workflow automatically creates
tags for all 27 submodules in the format `modules/<name>/v<version>`.

This enables Go's module system to resolve submodule versions correctly,
allowing users to import specific modules:
  go get github.com/gruntwork-io/terratest/modules/[email protected]

Features:
- Triggers automatically on release publish
- Can also be triggered manually for testing/re-running
- Skips tags that already exist
- Validates version format (X.Y.Z or X.Y.Z-suffix)
Add permissions.contents: write and explicit token to allow
the workflow to push tags to the repository.
Change from GITHUB_TOKEN to GH_TOKEN for pushing submodule tags.
Instead of hardcoding module list, dynamically find all go.mod files.
This way new modules are automatically tagged without workflow changes.

Excludes:
- Root go.mod
- Test directories (test/*)
Update all internal module dependencies to v0.55.0 to match the
upcoming release version.
- Pin goimports to v0.21.0 to avoid Go 1.24.0 requirement
- Replace go mod tidy with go work sync for workspace compatibility
- Add missing dependencies to all modules:
  - aws: AWS SDK v2
  - database: mssql, mysql, pq drivers
  - docker: gotest.tools
  - gcp: Google Cloud SDK, go-containerregistry
  - helm: k8s client-go, ytbx, dyff
  - k8s: client-go, apimachinery
  - logger: junit-report, logrus
  - slack: slack-go
  - terraform: HCL, terraform-json, copier, hcl2json
  - test-structure: go-commons

Note: Azure module has a code issue with deprecated SDK package
(services/preview/sql/mgmt/v3.0/sql) that needs separate fix.
- Add cmd/terratest_log_parser and cmd/pick-instance-type to go.work
- Create go.mod files for both cmd packages with proper replace directives
- Update cmd packages to use urfave/cli/v2 (breaking change from v1)
- Fix logger module to depend on local modules instead of monolithic terratest
- Add exclude directives to prevent ambiguous imports from go-commons

This fixes the CI build error:
"current directory outside modules listed in go.work or their selected dependencies"
…ility

The build-go-binaries helper from gruntwork-module-circleci-helpers doesn't
work with Go workspaces. Replace it with direct go build commands that
properly build from the workspace context.
@james00012 james00012 marked this pull request as draft December 3, 2025 16:47
@james00012 james00012 force-pushed the feature/complete-modularization branch from af54abe to 0afdaf8 Compare December 3, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants