-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: Avoid discovering dependencies if they are disabled #5119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…scovery' into fix/fixing-cycle-detection-in-discovery
📝 WalkthroughWalkthroughThe changes add logic to skip disabled dependencies during path extraction in the discovery process. Test fixtures and integration tests validate that disabled dependencies with empty config paths do not trigger cycle detection errors while maintaining proper dependency discovery functionality. Changes
Sequence DiagramsequenceDiagram
participant Discovery as Discovery Process
participant DepLoop as Dependency Loop
participant DependencyA as Dependency (Enabled)
participant DependencyB as Dependency (Enabled=false)
participant PathList as Extracted Paths
Discovery->>DepLoop: iterate cfg.TerragruntDependencies
DepLoop->>DependencyA: check Enabled status
alt Enabled = false
DepLoop->>DepLoop: continue (skip processing)
else Enabled = true or nil
DepLoop->>DependencyA: validate ConfigPath
DependencyA->>PathList: append to paths
end
DepLoop->>DependencyB: check Enabled status
alt Enabled = false
DepLoop->>DepLoop: continue (SKIP)
Note over DepLoop,PathList: Disabled dependency not added to paths<br/>Prevents false cycle detection
end
DepLoop->>PathList: return extracted paths
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/discovery/discovery_test.go (1)
930-1040: Cycle tests look good; consider fixing a misleading commentThe two tests correctly cover:
- a real cycle (
foo↔bar) being detected, and- the same shape with one edge disabled not producing a cycle.
Minor nit: in
TestDiscoveryDoesntDetectCycleWhenDisabledthe comment aboveCycleCheckstill says “Verify that a cycle is detected”, which contradicts the assertion.You could clarify with a tiny edit:
- // Verify that a cycle is detected + // Verify that no cycle is detected
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
internal/discovery/discovery.go(1 hunks)internal/discovery/discovery_test.go(1 hunks)test/fixtures/regressions/disabled-dependency-empty-config-path/modules/id/main.tf(1 hunks)test/fixtures/regressions/disabled-dependency-empty-config-path/root.hcl(1 hunks)test/fixtures/regressions/disabled-dependency-empty-config-path/unit-a/terragrunt.hcl(1 hunks)test/fixtures/regressions/disabled-dependency-empty-config-path/unit-b/terragrunt.hcl(1 hunks)test/integration_regressions_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/discovery_test.gointernal/discovery/discovery.gotest/integration_regressions_test.go
🧠 Learnings (4)
📚 Learning: 2025-02-10T23:20:04.295Z
Learnt from: yhakbar
Repo: gruntwork-io/terragrunt PR: 3868
File: docs-starlight/patches/@astrojs%2Fstarlight@0.31.1.patch: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/regressions/disabled-dependency-empty-config-path/unit-a/terragrunt.hcl
📚 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/regressions/disabled-dependency-empty-config-path/unit-a/terragrunt.hcltest/fixtures/regressions/disabled-dependency-empty-config-path/unit-b/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:
internal/discovery/discovery.go
📚 Learning: 2025-02-10T13:36:19.542Z
Learnt from: levkohimins
Repo: gruntwork-io/terragrunt PR: 3723
File: cli/commands/stack/action.go:160-160
Timestamp: 2025-02-10T13:36:19.542Z
Learning: The project uses a custom error package `github.com/gruntwork-io/terragrunt/internal/errors` which provides similar functionality to `fmt.Errorf` but includes stack traces. Prefer using this package's error functions (e.g., `errors.Errorf`, `errors.New`) over the standard library's error handling.
Applied to files:
internal/discovery/discovery.go
🧬 Code graph analysis (2)
internal/discovery/discovery_test.go (3)
options/options.go (1)
NewTerragruntOptions(380-382)test/helpers/logger/logger.go (1)
CreateLogger(9-14)internal/discovery/constructor.go (1)
NewDiscovery(153-172)
test/integration_regressions_test.go (2)
test/helpers/package.go (4)
CleanupTerraformFolder(882-889)CopyEnvironment(89-105)CreateGitRepo(1103-1108)RunTerragruntCommandWithOutput(1007-1011)util/file.go (1)
JoinPath(626-628)
⏰ 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). (2)
- GitHub Check: integration_tests / Test (AWS Tofu)
- GitHub Check: Pull Request has non-contributor approval
🔇 Additional comments (7)
test/fixtures/regressions/disabled-dependency-empty-config-path/root.hcl (1)
1-1: Minimal root fixture is fineSingle-line comment is enough for this regression fixture and keeps the root config intentionally empty.
internal/discovery/discovery.go (1)
1379-1395: Skipping disabled dependencies in path extraction matches desired semanticsShort‑circuiting when
dependency.Enabledis explicitlyfalseensures disabled dependencies don’t contribute edges to the dependency graph or triggerconfig_pathvalidation/empty‑path errors, which is exactly what the regression tests exercise.test/fixtures/regressions/disabled-dependency-empty-config-path/unit-a/terragrunt.hcl (1)
1-9: Unit‑a fixture is clear and minimalIncluding
root.hcl, wiringterraform.sourceto../modules/id, and leavinginputsempty keeps this unit focused and suitable as a simple peer for the regression scenario.test/integration_regressions_test.go (2)
16-23: New regression fixture constant is consistentThe
testFixtureDisabledDependencyEmptyConfigPathconstant matches the new fixture path and aligns with the existing naming pattern for regression fixtures.
376-421: Integration test robustly captures the disabled‑dependency regression
TestDisabledDependencyEmptyConfigPath_NoCycleErrorexercises both a directplanonunit-band arun --all planfrom the fixture root, asserting:
- no error exit,
- no “cycle”/“Cycle detected” messages, and
- no “has empty config_path” message.
This is a solid end‑to‑end guard for the fix.
test/fixtures/regressions/disabled-dependency-empty-config-path/unit-b/terragrunt.hcl (1)
1-31: Fixture accurately encodes “disabled dependency with empty config_path”Defining
unit_a_path = ""and usingconfig_path = try(local.unit_a_path, "")together withenabled = falseis a precise repro for the regression, and guarding output access withtry(dependency.unit_a.outputs.random_string, "")keeps evaluation safe when the dependency is ignored.test/fixtures/regressions/disabled-dependency-empty-config-path/modules/id/main.tf (1)
1-32: ID helper module fixture is straightforward and reusableThe small
random_string-based module with prefix/suffix/separator variables and anidoutput is clean and generic, appropriate as a shared building block for the regression fixtures.
Description
Fixes #4977.
TODOs
Read the Gruntwork contribution guidelines.
Release Notes (draft)
Added / Removed / Updated [X].
Migration Guide
Summary by CodeRabbit
Release Notes