Skip to content

Commit 84f66af

Browse files
Agent Orchestratorclaude
andcommitted
Fix include_patterns ignored for terragrunt blocks without direct changes
This commit fixes issue #2485 where include_patterns were only evaluated when at least one project had direct file changes in its root directory. The bug was in the HandleYamlProjectGeneration function where the entire terragrunt block processing was wrapped in a checkBlockInChangedFiles() conditional. This prevented include_patterns from being merged into projects when only files matching the include_patterns changed (but not files in the project's root directory). Changes: - Removed the checkBlockInChangedFiles() conditional wrapper for terragrunt block processing - Terragrunt projects are now always generated for blocks - include_patterns and exclude_patterns are always merged, allowing pattern matching to occur in GetModifiedProjects() regardless of direct changes This ensures consistent behavior between terragrunt and non-terragrunt blocks, where include_patterns are evaluated independently of direct project changes. Fixes #2485 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 08c18b3 commit 84f66af

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed

libs/digger_config/digger_config.go

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -419,57 +419,55 @@ func HandleYamlProjectGeneration(config *DiggerConfigYaml, terraformDir string,
419419
// if blocks of include/exclude patterns defined
420420
for _, b := range config.GenerateProjectsConfig.Blocks {
421421
if b.Terragrunt == true {
422-
if checkBlockInChangedFiles(*b.RootDir, changedFiles) {
423-
slog.Info("generating terragrunt projects for block",
424-
"blockName", b.BlockName,
425-
"rootDir", *b.RootDir)
426-
427-
workflow := "default"
428-
if b.Workflow != "" {
429-
workflow = b.Workflow
430-
}
422+
slog.Info("generating terragrunt projects for block",
423+
"blockName", b.BlockName,
424+
"rootDir", *b.RootDir)
431425

432-
// load the parsing config and override the block values
433-
tgParsingConfig := b.TerragruntParsingConfig
434-
if tgParsingConfig == nil {
435-
tgParsingConfig = &TerragruntParsingConfig{}
436-
}
437-
tgParsingConfig.CreateProjectName = true
438-
tgParsingConfig.DefaultWorkflow = workflow
439-
tgParsingConfig.WorkflowFile = b.WorkflowFile
440-
tgParsingConfig.FilterPaths = []string{path.Join(terraformDir, *b.RootDir)}
441-
tgParsingConfig.AwsRoleToAssume = b.AwsRoleToAssume
442-
tgParsingConfig.AwsCognitoOidcConfig = b.AwsCognitoOidcConfig
443-
444-
_, err := hydrateDiggerConfigYamlWithTerragrunt(config, *tgParsingConfig, terraformDir, b.BlockName, nil)
445-
if err != nil {
446-
slog.Error("failed to hydrate config with terragrunt",
447-
"error", err,
448-
"blockName", b.BlockName)
449-
return nil, err
450-
}
451-
if len(b.IncludePatterns) > 0 || len(b.ExcludePatterns) > 0 {
452-
for _, project := range config.Projects {
453-
if project.BlockName == b.BlockName && project.Terragrunt {
454-
if len(b.IncludePatterns) > 0 {
455-
project.IncludePatterns = append(project.IncludePatterns, b.IncludePatterns...)
456-
slog.Debug("merged include_patterns for terragrunt project",
457-
"projectName", project.Name,
458-
"blockName", b.BlockName,
459-
"includePatterns", project.IncludePatterns)
460-
}
461-
if len(b.ExcludePatterns) > 0 {
462-
project.ExcludePatterns = append(project.ExcludePatterns, b.ExcludePatterns...)
463-
slog.Debug("merged exclude_patterns for terragrunt project",
464-
"projectName", project.Name,
465-
"blockName", b.BlockName,
466-
"excludePatterns", project.ExcludePatterns)
467-
}
426+
workflow := "default"
427+
if b.Workflow != "" {
428+
workflow = b.Workflow
429+
}
430+
431+
// load the parsing config and override the block values
432+
tgParsingConfig := b.TerragruntParsingConfig
433+
if tgParsingConfig == nil {
434+
tgParsingConfig = &TerragruntParsingConfig{}
435+
}
436+
tgParsingConfig.CreateProjectName = true
437+
tgParsingConfig.DefaultWorkflow = workflow
438+
tgParsingConfig.WorkflowFile = b.WorkflowFile
439+
tgParsingConfig.FilterPaths = []string{path.Join(terraformDir, *b.RootDir)}
440+
tgParsingConfig.AwsRoleToAssume = b.AwsRoleToAssume
441+
tgParsingConfig.AwsCognitoOidcConfig = b.AwsCognitoOidcConfig
442+
443+
_, err := hydrateDiggerConfigYamlWithTerragrunt(config, *tgParsingConfig, terraformDir, b.BlockName, nil)
444+
if err != nil {
445+
slog.Error("failed to hydrate config with terragrunt",
446+
"error", err,
447+
"blockName", b.BlockName)
448+
return nil, err
449+
}
450+
// Always merge include_patterns and exclude_patterns, regardless of direct changes
451+
// This ensures patterns are evaluated even when only files matching include_patterns change
452+
if len(b.IncludePatterns) > 0 || len(b.ExcludePatterns) > 0 {
453+
for _, project := range config.Projects {
454+
if project.BlockName == b.BlockName && project.Terragrunt {
455+
if len(b.IncludePatterns) > 0 {
456+
project.IncludePatterns = append(project.IncludePatterns, b.IncludePatterns...)
457+
slog.Debug("merged include_patterns for terragrunt project",
458+
"projectName", project.Name,
459+
"blockName", b.BlockName,
460+
"includePatterns", project.IncludePatterns)
461+
}
462+
if len(b.ExcludePatterns) > 0 {
463+
project.ExcludePatterns = append(project.ExcludePatterns, b.ExcludePatterns...)
464+
slog.Debug("merged exclude_patterns for terragrunt project",
465+
"projectName", project.Name,
466+
"blockName", b.BlockName,
467+
"excludePatterns", project.ExcludePatterns)
468468
}
469469
}
470470
}
471-
} else {
472-
slog.Debug("skipping block due to no changed files", "blockName", b.BlockName)
473471
}
474472
} else {
475473
includePatterns = []string{b.Include}

0 commit comments

Comments
 (0)