8000 feat(terragrunt): Separate terragrunt and terraform arguments by james00012 · Pull Request #1581 · gruntwork-io/terratest · GitHub
[go: up one dir, main page]

Skip to content

Conversation

james00012
Copy link
Contributor

Summary

This PR refactors the terragrunt module to explicitly separate terragrunt-specific arguments from terraform command arguments, improving API clarity and usability.

Motivation

The previous implementation used a single ExtraArgs field for all arguments, making it unclear which arguments were for terragrunt vs terraform. The -- separator logic was also handled inconsistently across different commands.

Changes

  • Options struct refactoring: Replaced single ExtraArgs field with:
    • TerragruntArgs: For terragrunt-specific flags (e.g., --no-color, --terragrunt-log-level)
    • TerraformArgs: For terraform commands passed after -- separator (e.g., plan, apply, -upgrade)
  • Automatic separator handling: The -- separator is now automatically added when TerraformArgs are present
  • Test updates: All tests updated to use the new argument structure

Benefits

  • ✅ Clear separation of concerns between terragrunt and terraform arguments
  • ✅ Automatic handling of -- separator reduces boilerplate
  • ✅ Better type safety - prevents accidental mixing of argument types
  • ✅ More intuitive and maintainable API

Testing

All existing tests have been updated and are passing:

go test ./modules/terragrunt -v
# PASS
# ok github.com/gruntwork-io/terratest/modules/terragrunt

Breaking Changes

This is a breaking change for the beta terragrunt module. Users will need to update their code to use TerragruntArgs and TerraformArgs instead of ExtraArgs.

Migration Example

Before:

options := &terragrunt.Options{
    TerragruntDir: "/path/to/config",
    ExtraArgs: []string{"--no-color", "plan", "-out=tfplan"},
}

After:

options := &terragrunt.Options{
    TerragruntDir: "/path/to/config",
    TerragruntArgs: []string{"--no-color"},
    TerraformArgs: []string{"plan", "-out=tfplan"},
}

Refactor the terragrunt module to clearly separate terragrunt-specific arguments from terraform command arguments. This improves API clarity and makes the intended use of arguments explicit.

Changes:
- Replace single ExtraArgs field with TerragruntArgs and TerraformArgs
- Automatically handle -- separator when TerraformArgs are present
- Update all tests to use the new argument structure

Benefits:
- Clear separation between terragrunt flags (--no-color, --terragrunt-log-level) and terraform commands (plan, apply, -upgrade)
- Automatic separator handling reduces boilerplate
- Better type safety prevents mixing of argument types
- More maintainable and intuitive API
@james00012 james00012 self-assigned this Aug 13, 2025
@james00012 james00012 merged commit c0a1ec8 into main Aug 15, 2025
2 of 3 checks passed
@james00012 james00012 deleted the feat/separate-terragrunt-terraform-args branch August 15, 2025 12:34
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
0