Skip to content

fix(terragrunt_providers_lock, terragrunt_validate: Properly handle arguments passed from terragrunt to TF#939

Merged
MaxymVlasov merged 5 commits intoantonbabenko:masterfrom
ajax-kovtunov-o:patch-1
Oct 9, 2025
Merged

fix(terragrunt_providers_lock, terragrunt_validate: Properly handle arguments passed from terragrunt to TF#939
MaxymVlasov merged 5 commits intoantonbabenko:masterfrom
ajax-kovtunov-o:patch-1

Conversation

@ajax-kovtunov-o
Copy link
Copy Markdown
Contributor

@ajax-kovtunov-o ajax-kovtunov-o commented Oct 7, 2025

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • This PR enhances existing functionality.

Description of your changes

How can we test changes

Copilot AI review requested due to automatic review settings October 7, 2025 13:28
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 7, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Restores compatibility of “providers lock” and “validate” hooks across Terragrunt versions, including 0.78+.
    • Ensures consistent behavior and exit codes when running per-directory and run-all operations.
  • Chores

    • Implemented version-aware command invocation to seamlessly support both newer and older Terragrunt releases.

Walkthrough

Per-dir hook logic now chooses a version-aware Terragrunt subcommand: for Terragrunt >= 0.78 it uses the run -- ... form (including run -- providers lock or run -- validate), otherwise it uses the legacy providers lock or validate invocation. Exit-code handling is unchanged.

Changes

Cohort / File(s) Summary
Terragrunt providers lock hook
hooks/terragrunt_providers_lock.sh
Add version check and initialize SUBCOMMAND/RUN_ALL_SUBCOMMAND arrays: use run -- providers lock (and run --all -- providers lock) for terragrunt >= 0.78, otherwise use legacy providers lock (run-all providers lock). Replace direct calls with terragrunt "${SUBCOMMAND[@]}" "${args[@]}" in per_dir_hook_unique_part; preserve exit handling.
Terragrunt validate hook
hooks/terragrunt_validate.sh
Same pattern as providers lock: add version-aware SUBCOMMAND (run -- validate vs validate) and RUN_ALL_SUBCOMMAND; replace direct terragrunt validate calls with terragrunt "${SUBCOMMAND[@]}" "${args[@]}" in per_dir_hook_unique_part.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Hook as Hook script
  participant TG as terragrunt

  Hook->>Hook: Check terragrunt version
  alt terragrunt >= 0.78
    Note right of Hook#DDEBF7: Use "run --" subcommand form
    Hook->>TG: terragrunt run -- <command> "${args[@]}"
    TG-->>Hook: exit (status)
  else terragrunt < 0.78
    Note right of Hook#F7E6D6: Use legacy subcommand form
    Hook->>TG: terragrunt <command> "${args[@]}"
    TG-->>Hook: exit (status)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

hook/terragrunt_providers_lock, hook/terragrunt_validate

Suggested reviewers

  • antonbabenko
  • yermulnik
  • MaxymVlasov

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ⚠️ Warning The title enumerates specific hook filenames and focuses on file-level details rather than succinctly summarizing the core change, making it overly long and less clear for someone scanning PR history. It also uses a generic phrase about handling arguments without mentioning the version-aware command updates that are the primary enhancement. Consider renaming the title to a concise summary of the main change, for example “fix: update terragrunt hooks to use version-aware SUBCOMMAND arrays and pass through arguments,” which highlights the central improvement without listing individual files.
Description Check ❓ Inconclusive The pull request description only contains the default template and a checkbox indicating enhancement, but it provides no details about the actual changes or how to test them. Please update the description to include a concise summary of the implemented changes and clear instructions for how reviewers can test the new behavior.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Updates the terragrunt providers lock hook to use conditional command execution based on Terragrunt version, supporting both legacy and new command structures.

  • Introduces version-based conditional logic to handle Terragrunt version differences
  • Adds support for new run --all command structure for Terragrunt 0.78+
  • Maintains backward compatibility with older Terragrunt versions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread hooks/terragrunt_providers_lock.sh Outdated
Comment thread hooks/terragrunt_providers_lock.sh Outdated
@ajax-kovtunov-o ajax-kovtunov-o changed the title Update with using new command terragrunt_providers_lock.sh feat(terragrunt_providers_lock) - Update with using new command Oct 7, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e63792 and 6c4fad0.

📒 Files selected for processing (1)
  • hooks/terragrunt_providers_lock.sh (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-13T19:34:00.317Z
Learnt from: jannis-a
PR: antonbabenko/pre-commit-terraform#933
File: hooks/terragrunt_providers_lock.sh:18-21
Timestamp: 2025-09-13T19:34:00.317Z
Learning: In terragrunt hooks, the `--` separator should only be added before Terraform commands that are invoked through Terragrunt (like `providers lock`, `validate`), but not before native Terragrunt commands (like `hcl validate`). The separator tells Terragrunt to pass subsequent arguments to the underlying Terraform command, which is not applicable for Terragrunt's own commands.

Applied to files:

  • hooks/terragrunt_providers_lock.sh
🧬 Code graph analysis (1)
hooks/terragrunt_providers_lock.sh (1)
hooks/_common.sh (1)
  • common::terragrunt_version_ge_0.78 (622-639)
🔇 Additional comments (1)
hooks/terragrunt_providers_lock.sh (1)

17-21: LGTM: Version-based command setup is correct.

The version-dependent initialization of RUN_ALL_SUBCOMMAND properly distinguishes between the new run --all syntax (>= 0.78) and the legacy run-all syntax. This array is correctly consumed by run_hook_on_whole_repo at line 76.

Comment thread hooks/terragrunt_providers_lock.sh Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Copy Markdown
Collaborator

@yermulnik yermulnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution.
I think it is best to follow the pattern already established for run --all (and implemented in e.g. terragrunt_validate_inputs.sh). For this, could you please update main function to have the below:

  if common::terragrunt_version_ge_0.78; then
    local -ra SUBCOMMAND=(run -- providers lock)
    local -ra RUN_ALL_SUBCOMMAND=(run --all -- providers lock)
  else
    local -ra SUBCOMMAND=(providers lock)
    local -ra RUN_ALL_SUBCOMMAND=(run-all providers lock)
  fi

And then just re-use in per_dir_hook_unique_part function instead of adding new if-conditional:

  terragrunt "${SUBCOMMAND[@]}" "${args[@]}"

Does this sound reasonable to you?

The terragrunt_validate.sh seems to need the same update. WDYT will you be up to update it too please?

Comment thread hooks/terragrunt_providers_lock.sh Outdated
Co-authored-by: George Yermulnik (Georgii Iermulnik) <yz@yz.kiev.ua>
@yermulnik
Copy link
Copy Markdown
Collaborator

Thank you for the contribution. I think it is best to follow the pattern already established for run --all (and implemented in e.g. terragrunt_validate_inputs.sh). For this, could you please update main function to have the below:

  if common::terragrunt_version_ge_0.78; then
    local -ra SUBCOMMAND=(run -- providers lock)
    local -ra RUN_ALL_SUBCOMMAND=(run --all -- providers lock)
  else
    local -ra SUBCOMMAND=(providers lock)
    local -ra RUN_ALL_SUBCOMMAND=(run-all providers lock)
  fi

And then just re-use in per_dir_hook_unique_part function instead of adding new if-conditional:

  terragrunt "${SUBCOMMAND[@]}" "${args[@]}"

Does this sound reasonable to you?

The terragrunt_validate.sh seems to need the same update. WDYT will you be up to update it too please?

@ajax-kovtunov-o I can see you pushed the change and requested review, though I can't seem to see the change I suggested in the above quoted comment — is there a reason behind it? Thanks.

@yermulnik
Copy link
Copy Markdown
Collaborator

@ajax-kovtunov-o I can see you pushed the change and requested review, though I can't seem to see the change I suggested in the above quoted comment — is there a reason behind it? Thanks.

Let me know and I can push changes to your branch (you'll only need to allow us to push — see screenshot below):
image

@ajax-kovtunov-o
Copy link
Copy Markdown
Contributor Author

@yermulnik check

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2623db1 and 77a1fa8.

📒 Files selected for processing (2)
  • hooks/terragrunt_providers_lock.sh (2 hunks)
  • hooks/terragrunt_validate.sh (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hooks/terragrunt_providers_lock.sh
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: jannis-a
PR: antonbabenko/pre-commit-terraform#933
File: hooks/terragrunt_providers_lock.sh:18-21
Timestamp: 2025-09-13T19:34:00.317Z
Learning: In terragrunt hooks, the `--` separator should only be added before Terraform commands that are invoked through Terragrunt (like `providers lock`, `validate`), but not before native Terragrunt commands (like `hcl validate`). The separator tells Terragrunt to pass subsequent arguments to the underlying Terraform command, which is not applicable for Terragrunt's own commands.
📚 Learning: 2025-09-13T19:34:00.317Z
Learnt from: jannis-a
PR: antonbabenko/pre-commit-terraform#933
File: hooks/terragrunt_providers_lock.sh:18-21
Timestamp: 2025-09-13T19:34:00.317Z
Learning: In terragrunt hooks, the `--` separator should only be added before Terraform commands that are invoked through Terragrunt (like `providers lock`, `validate`), but not before native Terragrunt commands (like `hcl validate`). The separator tells Terragrunt to pass subsequent arguments to the underlying Terraform command, which is not applicable for Terragrunt's own commands.

Applied to files:

  • hooks/terragrunt_validate.sh

Comment thread hooks/terragrunt_validate.sh
@ajax-kovtunov-o
Copy link
Copy Markdown
Contributor Author

ajax-kovtunov-o commented Oct 8, 2025

@yermulnik if you want perform any edits - you permitted to do
Screenshot 2025-10-08 at 19 10 38

Copy link
Copy Markdown
Collaborator

@yermulnik yermulnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@MaxymVlasov Please review.

@yermulnik yermulnik changed the title feat(terragrunt_providers_lock) - Update with using new command feat(terragrunt_providers_lock): Update with using new command Oct 8, 2025
@ajax-kovtunov-o
Copy link
Copy Markdown
Contributor Author

I've tested this with the new terragrunt version 0.89.2, which doesn't support the old command. I assume it works.

Screenshot 2025-10-08 at 22 25 28

@yermulnik
Copy link
Copy Markdown
Collaborator

I've tested this with the new terragrunt version 0.89.2, which doesn't support the old command. I assume it works.

Sounds great. Appreciate it.
@MaxymVlasov will review when he's got a chance and this will get merged and released.

@ajax-kovtunov-o
Copy link
Copy Markdown
Contributor Author

@yermulnik, when can I expect the merge and release of the changes? If it won't be released soon, we may face the necessity to downgrade the terragrunt version.

@yermulnik
Copy link
Copy Markdown
Collaborator

@yermulnik, when can I expect the merge and release of the changes? If it won't be released soon, we may face the necessity to downgrade the terragrunt version.

Let me check with @MaxymVlasov

@MaxymVlasov MaxymVlasov changed the title feat(terragrunt_providers_lock): Update with using new command fix(terragrunt_providers_lock, terragrunt_validate: Properly handle arguments passed from terragrunt to TF Oct 9, 2025
@MaxymVlasov MaxymVlasov merged commit 718ff95 into antonbabenko:master Oct 9, 2025
42 of 45 checks passed
@ajax-kovtunov-o ajax-kovtunov-o deleted the patch-1 branch October 9, 2025 11:29
MaxymVlasov added a commit that referenced this pull request Oct 9, 2025
MaxymVlasov added a commit that referenced this pull request Oct 9, 2025
…dle arguments passed from terragrunt to TF (#939)
antonbabenko pushed a commit that referenced this pull request Oct 9, 2025
## [1.101.1](v1.101.0...v1.101.1) (2025-10-09)

### Bug Fixes

* **`terragrunt_providers_lock`, `terragrunt_validate`:** Properly handle arguments passed from terragrunt to TF ([#939](#939)) ([bae0525](bae0525))
@antonbabenko
Copy link
Copy Markdown
Owner

This PR is included in version 1.101.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants