From 84f66af01f486fcd4bfb49c1bf35eae600f58365 Mon Sep 17 00:00:00 2001 From: Agent Orchestrator Date: Sat, 13 Dec 2025 00:41:45 +0000 Subject: [PATCH] Fix include_patterns ignored for terragrunt blocks without direct changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- libs/digger_config/digger_config.go | 92 ++++++++++++++--------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/libs/digger_config/digger_config.go b/libs/digger_config/digger_config.go index 5e2b8d19c..2a0125073 100644 --- a/libs/digger_config/digger_config.go +++ b/libs/digger_config/digger_config.go @@ -419,57 +419,55 @@ func HandleYamlProjectGeneration(config *DiggerConfigYaml, terraformDir string, // if blocks of include/exclude patterns defined for _, b := range config.GenerateProjectsConfig.Blocks { if b.Terragrunt == true { - if checkBlockInChangedFiles(*b.RootDir, changedFiles) { - slog.Info("generating terragrunt projects for block", - "blockName", b.BlockName, - "rootDir", *b.RootDir) - - workflow := "default" - if b.Workflow != "" { - workflow = b.Workflow - } + slog.Info("generating terragrunt projects for block", + "blockName", b.BlockName, + "rootDir", *b.RootDir) - // load the parsing config and override the block values - tgParsingConfig := b.TerragruntParsingConfig - if tgParsingConfig == nil { - tgParsingConfig = &TerragruntParsingConfig{} - } - tgParsingConfig.CreateProjectName = true - tgParsingConfig.DefaultWorkflow = workflow - tgParsingConfig.WorkflowFile = b.WorkflowFile - tgParsingConfig.FilterPaths = []string{path.Join(terraformDir, *b.RootDir)} - tgParsingConfig.AwsRoleToAssume = b.AwsRoleToAssume - tgParsingConfig.AwsCognitoOidcConfig = b.AwsCognitoOidcConfig - - _, err := hydrateDiggerConfigYamlWithTerragrunt(config, *tgParsingConfig, terraformDir, b.BlockName, nil) - if err != nil { - slog.Error("failed to hydrate config with terragrunt", - "error", err, - "blockName", b.BlockName) - return nil, err - } - if len(b.IncludePatterns) > 0 || len(b.ExcludePatterns) > 0 { - for _, project := range config.Projects { - if project.BlockName == b.BlockName && project.Terragrunt { - if len(b.IncludePatterns) > 0 { - project.IncludePatterns = append(project.IncludePatterns, b.IncludePatterns...) - slog.Debug("merged include_patterns for terragrunt project", - "projectName", project.Name, - "blockName", b.BlockName, - "includePatterns", project.IncludePatterns) - } - if len(b.ExcludePatterns) > 0 { - project.ExcludePatterns = append(project.ExcludePatterns, b.ExcludePatterns...) - slog.Debug("merged exclude_patterns for terragrunt project", - "projectName", project.Name, - "blockName", b.BlockName, - "excludePatterns", project.ExcludePatterns) - } + workflow := "default" + if b.Workflow != "" { + workflow = b.Workflow + } + + // load the parsing config and override the block values + tgParsingConfig := b.TerragruntParsingConfig + if tgParsingConfig == nil { + tgParsingConfig = &TerragruntParsingConfig{} + } + tgParsingConfig.CreateProjectName = true + tgParsingConfig.DefaultWorkflow = workflow + tgParsingConfig.WorkflowFile = b.WorkflowFile + tgParsingConfig.FilterPaths = []string{path.Join(terraformDir, *b.RootDir)} + tgParsingConfig.AwsRoleToAssume = b.AwsRoleToAssume + tgParsingConfig.AwsCognitoOidcConfig = b.AwsCognitoOidcConfig + + _, err := hydrateDiggerConfigYamlWithTerragrunt(config, *tgParsingConfig, terraformDir, b.BlockName, nil) + if err != nil { + slog.Error("failed to hydrate config with terragrunt", + "error", err, + "blockName", b.BlockName) + return nil, err + } + // Always merge include_patterns and exclude_patterns, regardless of direct changes + // This ensures patterns are evaluated even when only files matching include_patterns change + if len(b.IncludePatterns) > 0 || len(b.ExcludePatterns) > 0 { + for _, project := range config.Projects { + if project.BlockName == b.BlockName && project.Terragrunt { + if len(b.IncludePatterns) > 0 { + project.IncludePatterns = append(project.IncludePatterns, b.IncludePatterns...) + slog.Debug("merged include_patterns for terragrunt project", + "projectName", project.Name, + "blockName", b.BlockName, + "includePatterns", project.IncludePatterns) + } + if len(b.ExcludePatterns) > 0 { + project.ExcludePatterns = append(project.ExcludePatterns, b.ExcludePatterns...) + slog.Debug("merged exclude_patterns for terragrunt project", + "projectName", project.Name, + "blockName", b.BlockName, + "excludePatterns", project.ExcludePatterns) } } } - } else { - slog.Debug("skipping block due to no changed files", "blockName", b.BlockName) } } else { includePatterns = []string{b.Include}