Skip to content

Conversation

@yhakbar
Copy link
Collaborator

@yhakbar yhakbar commented Dec 16, 2025

Description

Fixes regression on support for root terragrunt.hcl file.

TODOs

Read the Gruntwork contribution guidelines.

  • I authored this code entirely myself
  • I am submitting code based on open source software (e.g. MIT, MPL-2.0, Apache)]
  • I am adding or upgrading a dependency or adapted code and confirm it has a compatible open source license
  • Update the docs.
  • Run the relevant tests successfully, including pre-commit checks.
  • Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Added / Removed / Updated [X].

Migration Guide

Summary by CodeRabbit

  • Bug Fixes

    • Modified inclusion and exclusion path matching to use exact path matching instead of prefix-based matching. Previously, paths under a specified directory would be matched; now only exact directory paths are matched.
  • Tests

    • Added regression test to verify root Terragrunt configuration behavior and deprecated functionality continues to work correctly.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
terragrunt-docs Ready Ready Preview, Comment Dec 16, 2025 11:19pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2025

📝 Walkthrough

Walkthrough

This change modifies the discovery queue filtering logic to use exact path matching instead of prefix-based directory matching in inclusion and exclusion filters. It adds regression test fixtures for a root terragrunt.hcl scenario and introduces an integration test to validate the new filtering behavior.

Changes

Cohort / File(s) Change Summary
Core Filtering Logic
internal/discovery/queue_filters.go
Changes matchesInclude and matchesExclude functions to return true only when the cleaned path exactly equals a cleaned directory path, replacing previous HasPathPrefix behavior for narrower matching semantics.
Test Fixtures
test/fixtures/root-terragrunt-hcl-regression/bar/terragrunt.hcl, test/fixtures/root-terragrunt-hcl-regression/baz/terragrunt.hcl, test/fixtures/root-terragrunt-hcl-regression/foo/terragrunt.hcl
Adds three new Terragrunt configuration files that include a root configuration via deprecated find_in_parent_folders behavior and set terraform source to the current directory.
Integration Tests
test/integration_include_test.go
Adds new constant rootTerragruntHCLFixturePath and introduces TestTerragruntWorksWithRootTerragruntHCL regression test to validate root terragrunt.hcl exclusion and child config inclusion behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Duplicate test function: TestTerragruntWorksWithRootTerragruntHCL appears twice in test/integration_include_test.go—verify this is intentional or remove the duplicate.
  • Logic change impact: Review matchesInclude and matchesExclude modifications in queue_filters.go to ensure exact-path matching aligns with intended filtering behavior and doesn't break nested path scenarios.
  • Regression test coverage: Confirm the new test adequately validates the root terragrunt.hcl exclusion scenario across all three fixture paths.

Possibly related PRs

Suggested reviewers

  • ThisGuyCodes
  • denis256

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete. While it mentions the issue being fixed, it lacks detailed explanation of changes, has placeholder release notes, and no migration guide despite marking TODOs as complete. Expand the description to explain the technical changes made (e.g., exact path matching vs prefix matching), provide concrete release notes instead of 'Added/Removed/Updated [X]', and include a migration guide if backward incompatible changes were made.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing a regression related to supporting inclusion of the root terragrunt.hcl file.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/fixing-regression-on-terragrunt-hcl-as-root

📜 Recent 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 3c1148b and c61a840.

📒 Files selected for processing (5)
  • internal/discovery/queue_filters.go (2 hunks)
  • test/fixtures/root-terragrunt-hcl-regression/bar/terragrunt.hcl (1 hunks)
  • test/fixtures/root-terragrunt-hcl-regression/baz/terragrunt.hcl (1 hunks)
  • test/fixtures/root-terragrunt-hcl-regression/foo/terragrunt.hcl (1 hunks)
  • test/integration_include_test.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

⚙️ CodeRabbit configuration file

Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.

Files:

  • internal/discovery/queue_filters.go
  • test/integration_include_test.go
🧠 Learnings (5)
📓 Common learnings
Learnt from: ThisGuyCodes
Repo: gruntwork-io/terragrunt PR: 5041
File: test/fixtures/hclvalidate/valid/duplicate-attributes-in-required-providers/main.tf:2-7
Timestamp: 2025-11-03T04:40:01.000Z
Learning: In the terragrunt repository, test fixtures under test/fixtures/hclvalidate/valid/ are intentionally testing that INPUT validation succeeds even when Terraform code contains syntax errors or other issues unrelated to input validation (e.g., duplicate attributes, circular references, invalid locals). The "valid" designation means "valid for input validation purposes" not "syntactically valid Terraform/OpenTofu code".
Learnt from: jkarkoszka
Repo: gruntwork-io/terragrunt PR: 5116
File: test/integration_test.go:2785-2795
Timestamp: 2025-11-18T09:54:06.008Z
Learning: In Terragrunt, `read_terragrunt_config_with_cache` intentionally has different semantics than `read_terragrunt_config`: it caches the first parse result (including context like `original_terragrunt_dir`) and returns that cached value on subsequent calls to the same file, even if the calling context has changed. This is a performance optimization that trades context accuracy for speed. Tests showing different assertions between cached and non-cached variants for context-dependent values like `original_terragrunt_dir` are expected and correct.
📚 Learning: 2025-11-03T04:40:01.000Z
Learnt from: ThisGuyCodes
Repo: gruntwork-io/terragrunt PR: 5041
File: test/fixtures/hclvalidate/valid/duplicate-attributes-in-required-providers/main.tf:2-7
Timestamp: 2025-11-03T04:40:01.000Z
Learning: In the terragrunt repository, test fixtures under test/fixtures/hclvalidate/valid/ are intentionally testing that INPUT validation succeeds even when Terraform code contains syntax errors or other issues unrelated to input validation (e.g., duplicate attributes, circular references, invalid locals). The "valid" designation means "valid for input validation purposes" not "syntactically valid Terraform/OpenTofu code".

Applied to files:

  • test/fixtures/root-terragrunt-hcl-regression/bar/terragrunt.hcl
  • test/fixtures/root-terragrunt-hcl-regression/foo/terragrunt.hcl
  • test/fixtures/root-terragrunt-hcl-regression/baz/terragrunt.hcl
  • test/integration_include_test.go
📚 Learning: 2025-11-18T09:54:06.008Z
Learnt from: jkarkoszka
Repo: gruntwork-io/terragrunt PR: 5116
File: test/integration_test.go:2785-2795
Timestamp: 2025-11-18T09:54:06.008Z
Learning: In Terragrunt, `read_terragrunt_config_with_cache` intentionally has different semantics than `read_terragrunt_config`: it caches the first parse result (including context like `original_terragrunt_dir`) and returns that cached value on subsequent calls to the same file, even if the calling context has changed. This is a performance optimization that trades context accuracy for speed. Tests showing different assertions between cached and non-cached variants for context-dependent values like `original_terragrunt_dir` are expected and correct.

Applied to files:

  • test/fixtures/root-terragrunt-hcl-regression/bar/terragrunt.hcl
  • test/fixtures/root-terragrunt-hcl-regression/foo/terragrunt.hcl
  • test/fixtures/root-terragrunt-hcl-regression/baz/terragrunt.hcl
  • test/integration_include_test.go
📚 Learning: 2025-02-10T23:20:04.295Z
Learnt from: yhakbar
Repo: gruntwork-io/terragrunt PR: 3868
File: docs-starlight/patches/@astrojs%[email protected]:33-33
Timestamp: 2025-02-10T23:20:04.295Z
Learning: In Terragrunt projects, all `.hcl` files can be assumed to be Terragrunt configurations by default, with specific exceptions like `.terraform.lock.hcl` that need explicit handling.

Applied to files:

  • test/fixtures/root-terragrunt-hcl-regression/bar/terragrunt.hcl
  • test/fixtures/root-terragrunt-hcl-regression/foo/terragrunt.hcl
  • test/fixtures/root-terragrunt-hcl-regression/baz/terragrunt.hcl
📚 Learning: 2025-08-19T16:05:54.723Z
Learnt from: Resonance1584
Repo: gruntwork-io/terragrunt PR: 4683
File: go.mod:86-90
Timestamp: 2025-08-19T16:05:54.723Z
Learning: When analyzing Go module dependencies for removal, always check for both direct imports and API usage across all Go files in the repository, not just a quick search. The github.com/mattn/go-zglob library is used for filesystem walking and glob expansion in multiple Terragrunt files including util/file.go, format commands, and AWS provider patch functionality.

Applied to files:

  • test/fixtures/root-terragrunt-hcl-regression/bar/terragrunt.hcl
  • test/fixtures/root-terragrunt-hcl-regression/foo/terragrunt.hcl
  • test/fixtures/root-terragrunt-hcl-regression/baz/terragrunt.hcl
🧬 Code graph analysis (1)
internal/discovery/queue_filters.go (1)
util/file.go (1)
  • CleanPath (637-639)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pull Request has non-contributor approval
🔇 Additional comments (7)
test/fixtures/root-terragrunt-hcl-regression/bar/terragrunt.hcl (1)

1-8: LGTM!

Test fixture correctly exercises the deprecated find_in_parent_folders("terragrunt.hcl") include pattern. The comment documenting the deprecated behavior is helpful for future maintainers.

test/fixtures/root-terragrunt-hcl-regression/foo/terragrunt.hcl (1)

1-8: LGTM!

Consistent fixture structure with the other child directories in this regression test set.

test/fixtures/root-terragrunt-hcl-regression/baz/terragrunt.hcl (1)

1-8: LGTM!

Third child fixture completing the test set for validating queue inclusion/exclusion behavior.

internal/discovery/queue_filters.go (2)

49-53: Correct fix for the regression.

The exact match ensures --queue-exclude-dir=. excludes only the root directory, allowing child configs (bar, baz, foo) to remain in the queue while the root terragrunt.hcl is excluded as a runnable unit.


31-35: Behavioral change from prefix to exact path matching is correct for the regression fix.

Switching to exact equality ensures --queue-exclude-dir=. only matches the root directory itself, not all subdirectories. The pattern-based matching (lines 25-29) still provides glob functionality for broader matches when needed. The integration tests confirm this dual behavior works as intended: exact paths match literally, while patterns like */aws and **/module-gce-c use glob matching.

test/integration_include_test.go (2)

18-29: LGTM!

New constant rootTerragruntHCLFixturePath follows existing naming conventions and aligns with other fixture path constants.


272-319: Comprehensive regression test with excellent documentation.

The test thoroughly validates:

  1. Root directory is skipped for parsing when excluded
  2. Child configs can still include the root terragrunt.hcl
  3. Child units are discovered and queued
  4. Root is excluded from execution while children are not

The detailed comments (lines 275-282) clearly explain the regression scenario, which is valuable for future maintainers.


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

@yhakbar yhakbar force-pushed the fix/fixing-regression-on-terragrunt-hcl-as-root branch from 64d90ce to c61a840 Compare December 16, 2025 23:18
@yhakbar yhakbar marked this pull request as ready for review December 16, 2025 23:51
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