Skip to content

Commit 5b5f13b

Browse files
committed
fix: Fixing TestHclvalidateInvalidConfigPath
1 parent 0412ffc commit 5b5f13b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

internal/discovery/discovery.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,14 @@ func Parse(
440440
//nolint: contextcheck
441441
cfg, err = config.PartialParseConfigFile(parsingCtx, l, parseOpts.TerragruntConfigPath, nil)
442442
if err != nil {
443+
if suppressParseErrors {
444+
var notFoundErr config.TerragruntConfigNotFoundError
445+
if stderrs.As(err, &notFoundErr) {
446+
l.Debugf("Skipping missing config during discovery: %s", parseOpts.TerragruntConfigPath)
447+
return nil
448+
}
449+
}
450+
443451
// Treat include-only/no-settings configs as non-fatal during discovery when suppression is enabled
444452
if suppressParseErrors && containsNoSettingsError(err) {
445453
l.Debugf("Skipping include-only config during discovery: %s", parseOpts.TerragruntConfigPath)
@@ -1304,6 +1312,12 @@ func determineStartingComponentsFromExpressions(
13041312
// extractDependencyPaths extracts all dependency paths from a Terragrunt configuration.
13051313
// It returns the list of absolute dependency paths and any errors encountered during extraction.
13061314
func extractDependencyPaths(cfg *config.TerragruntConfig, component component.Component) ([]string, error) {
1315+
// Some discovery passes may encounter components that don't actually have a config file (e.g., directories that
1316+
// exist under the working dir but have no terragrunt.hcl). Treat those as having no dependencies.
1317+
if cfg == nil {
1318+
return nil, nil
1319+
}
1320+
13071321
deduped := make(map[string]struct{})
13081322

13091323
var errs []error

test/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ func TestHclvalidateInvalidConfigPath(t *testing.T) {
796796
stdout, _, err := helpers.RunTerragruntCommandWithOutput(
797797
t,
798798
fmt.Sprintf(
799-
"terragrunt hcl validate --all --working-dir %s --json --show-config-path",
799+
"terragrunt hcl validate --working-dir %s --json --show-config-path",
800800
rootPath,
801801
),
802802
)

0 commit comments

Comments
 (0)