Skip to content

Commit 5adb284

Browse files
authored
Feat/exclude drift (#2650)
* feat: include and exclude driff patterns * chore: dep * fix: truncate chars over gh limit * docs: update digger reference to include new drift includes * docs: phrasing
1 parent e0137c5 commit 5adb284

9 files changed

Lines changed: 82 additions & 34 deletions

File tree

backend/go.sum

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
ariga.io/atlas-go-sdk v0.7.2 h1:pvS8tKVeRQuqdETBqj5qAQtVbQE88Gya6bOfY8YF3vU=
22
ariga.io/atlas-go-sdk v0.7.2/go.mod h1:cFq7bnvHgKTWHCsU46mtkGxdl41rx2o7SjaLoh6cO8M=
3-
ariga.io/atlas-provider-gorm v0.5.0 h1:DqYNWroKUiXmx2N6nf/I9lIWu6fpgB6OQx/JoelCTes=
4-
ariga.io/atlas-provider-gorm v0.5.0/go.mod h1:8m6+N6+IgWMzPcR63c9sNOBoxfNk6yV6txBZBrgLg1o=
53
ariga.io/atlas-provider-gorm v0.5.4 h1:64xboUDrP+JHdZOy4juPydHT5UP1kY152b5Gh/xNzmM=
64
ariga.io/atlas-provider-gorm v0.5.4/go.mod h1:cXt4kxq8KIldPXHoWXC0HvSr8dVI0dIykZt3MZ4AmqE=
75
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805 h1:u2qwJeEvnypw+OCPUHmoZE3IqwfuN5kgDfo5MLzpNM0=
@@ -759,10 +757,6 @@ github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm
759757
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
760758
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
761759
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM=
762-
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
763-
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
764-
github.com/alecthomas/kong v1.9.0 h1:Wgg0ll5Ys7xDnpgYBuBn/wPeLGAuK0NvYmEcisJgrIs=
765-
github.com/alecthomas/kong v1.9.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
766760
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
767761
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
768762
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -2847,7 +2841,6 @@ gorm.io/gorm v1.23.7/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
28472841
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
28482842
gorm.io/gorm v1.23.10/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
28492843
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
2850-
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
28512844
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
28522845
gorm.io/gorm v1.30.1 h1:lSHg33jJTBxs2mgJRfRZeLDG+WZaHYCk3Wtfl6Ngzo4=
28532846
gorm.io/gorm v1.30.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=

cli/pkg/drift/github_issue.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ func (ghi *GithubIssueNotification) SendNotificationForProject(projectName strin
1616
log.Printf("Info: Sending drift notification regarding project: %v", projectName)
1717
title := fmt.Sprintf("Drift detected in project: %v", projectName)
1818
message := fmt.Sprintf(":bangbang: Drift detected in digger project %v details below: \n\n```\n%v\n```", projectName, plan)
19+
const maxLen = 65536
20+
const truncMsg = "\n\n> ⚠️ Output truncated: plan exceeds GitHub's 65536 character limit. See job logs for full output."
21+
if len(message) > maxLen {
22+
message = message[:maxLen-len(truncMsg)] + truncMsg
23+
}
1924
existingIssues, err := (*ghi.GithubService).ListIssues()
2025
if err != nil {
2126
log.Printf("failed to retrieve issues: %v", err)

cli/pkg/github/github.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ func GitHubCI(lock core_locking.Lock, policyCheckerProvider core_policy.PolicyCh
215215
continue
216216
}
217217
}
218+
if len(diggerConfig.DriftIncludePatterns) > 0 || len(diggerConfig.DriftExcludePatterns) > 0 {
219+
if !digger_config.MatchIncludeExcludePatternsToFile(projectConfig.Dir, diggerConfig.DriftIncludePatterns, diggerConfig.DriftExcludePatterns) {
220+
slog.Info("Project excluded by drift patterns, skipping", "project", projectConfig.Name, "dir", projectConfig.Dir)
221+
continue
222+
}
223+
}
218224
workflow := diggerConfig.Workflows[projectConfig.Workflow]
219225

220226
stateEnvVars, commandEnvVars := digger_config.CollectTerraformEnvConfig(workflow.EnvVars, true)

docs/ce/drift/backendless-scoping-projects.mdx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
---
22
title: "Backendless: Scope Drift to Specific Projects"
3-
description: "Scope backendless drift checks to selected projects using dedicated config files"
3+
description: "Scope backendless drift checks to selected projects using dedicated config file or patterns"
44
---
55

6-
In Backendless mode, scope drift by pointing your scheduled workflow at a dedicated config file.
76

8-
## Approach
7+
8+
9+
In Backendless mode, digger provides two means scoping drift detection.
10+
11+
12+
13+
## Using dedicated config
914

1015
- Create a dedicated `digger.yml` that lists only the projects or blocks you want scanned.
1116
- Point your drift workflow to that file using the `digger-filename` input.
@@ -57,7 +62,31 @@ jobs:
5762
digger-filename: digger-drift-dev.yml
5863
```
5964
65+
## Using drift patterns
66+
67+
Add `drift_include_patterns` and `drift_exclude_patterns` under `generate_projects` in your main `digger.yml`:
68+
69+
```yaml
70+
generate_projects:
71+
blocks:
72+
- block_name: infra
73+
root_dir: "infra/"
74+
workflow: default
75+
include: "**"
76+
drift_include_patterns:
77+
- "infra/prod/**"
78+
- "infra/staging/**"
79+
drift_exclude_patterns:
80+
- "infra/_global/**"
81+
```
82+
83+
Only projects whose `dir` matches an include pattern and does not match an exclude pattern will run drift detection. Exclude patterns are evaluated after include patterns.
84+
6085
## Notes
6186

62-
- There is no per-project drift filter in the action; scoping via a dedicated config file is the recommended approach.
63-
- You can also mark projects with `drift_detection: false` in your main config to disable drift checks for them.
87+
- Patterns use [doublestar](https://github.com/bmatcuk/doublestar) glob matching against the project directory path.
88+
- Both fields default to `[]`. If `drift_include_patterns` is empty, all projects are included.
89+
90+
## Related
91+
92+
- [Backendless Drift via GitHub Actions](/ce/drift/backendless-github-actions)

docs/ce/reference/digger.yml.mdx

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -227,29 +227,17 @@ workflows:
227227
Workflows and configurations to run on events. See [Workflow Configuration](#workflow-configuration).
228228
</ParamField>
229229

230-
<AccordionGroup>
231-
<Accordion title="Reporting Configuration">
232-
Configure reporting options using the `reporting` key.
233-
234-
<ParamField path="reporting.ai_summary" type="boolean" default="false">
235-
Enable AI-generated summaries of plan output. See [AI Summaries](/ce/features/ai-summaries).
236-
</ParamField>
237-
238-
<ParamField path="reporting.comments_enabled" type="boolean" default="true">
239-
Enable posting plan/apply results as PR comments.
240-
</ParamField>
241-
</Accordion>
230+
<ParamField path="reporting.ai_summary" type="boolean" default="false">
231+
Enable AI-generated summaries of plan output. See [AI Summaries](/ce/features/ai-summaries).
232+
</ParamField>
242233

243-
<Accordion title="Dependency Configuration">
244-
Configure dependency handling using the `dependency_configuration` key.
234+
<ParamField path="reporting.comments_enabled" type="boolean" default="true">
235+
Enable posting plan/apply results as PR comments.
236+
</ParamField>
245237

246-
<ParamField path="dependency_configuration.mode" type="string" default="hard">
247-
Dependency execution mode:
248-
- `hard` - Execute dependency projects even if they weren't changed
249-
- `soft` - Skip dependency projects if they weren't changed
250-
</ParamField>
251-
</Accordion>
252-
</AccordionGroup>
238+
<ParamField path="dependency_configuration.mode" type="string" default="hard">
239+
Dependency execution mode: `hard` executes dependency projects even if unchanged, `soft` skips them if unchanged.
240+
</ParamField>
253241

254242
---
255243

@@ -389,6 +377,14 @@ Automatically generate projects from directory structure using the `generate_pro
389377
Terragrunt-specific parsing configuration. See [Terragrunt Parsing](/ce/reference/terragrunt-parsing) for all options.
390378
</ParamField>
391379

380+
<ParamField path="drift_include_patterns" type="array" default="[]">
381+
Glob patterns matched against each project's `dir`. Only matching projects run drift detection. If empty, all projects are included. See [Backendless: Scope Drift to Specific Projects](/ce/drift/backendless-scoping-projects).
382+
</ParamField>
383+
384+
<ParamField path="drift_exclude_patterns" type="array" default="[]">
385+
Glob patterns matched against each project's `dir`. Matching projects are skipped during drift detection. Evaluated after `drift_include_patterns`.
386+
</ParamField>
387+
392388
<ParamField path="aws_role_to_assume" type="object">
393389
Default AWS role configuration for all generated projects. See [AWS Role Configuration](#aws-role-configuration).
394390
</ParamField>
@@ -512,7 +508,7 @@ Define custom workflows using the `workflows` map. Each workflow can have its ow
512508
Configure plan and apply stages.
513509

514510
<ParamField path="filter_regex" type="string">
515-
Regular expression to filter which files trigger this stage.
511+
Regular expression to mask sensitive values from plan output and PR comments. Matches are replaced with `<REDACTED>`. See [Masking sensitive values](/ce/howto/masking-sensitive-values).
516512
</ParamField>
517513

518514
<ParamField path="steps" type="array" default="[]">

drift/controllers/drift.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ func (mc MainController) TriggerDriftRunForProject(c *gin.Context) {
8282
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("could not find project %v in digger.yml", theProject)})
8383
return
8484
}
85+
86+
// Apply drift include/exclude patterns from generate_projects config
87+
if len(config.DriftIncludePatterns) > 0 || len(config.DriftExcludePatterns) > 0 {
88+
if !dg_configuration.MatchIncludeExcludePatternsToFile(theProject.Dir, config.DriftIncludePatterns, config.DriftExcludePatterns) {
89+
log.Printf("Project %v dir %v excluded by drift patterns, skipping", project.Name, theProject.Dir)
90+
c.String(http.StatusOK, "project excluded by drift patterns")
91+
return
92+
}
93+
}
94+
8595
projects := []dg_configuration.Project{*theProject}
8696

8797
jobsForImpactedProjects, err := generic.CreateJobsForProjects(projects, command, "drift", repoFullName, "digger", config.Workflows, &issueNumber, nil, branch, branch, false)

libs/digger_config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type DiggerConfig struct {
3131
TraverseToNestedProjects bool
3232
Reporting ReporterConfig
3333
ReportTerraformOutputs bool
34+
DriftExcludePatterns []string
35+
DriftIncludePatterns []string
3436
}
3537

3638
type ReporterConfig struct {

libs/digger_config/converters.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ func ConvertDiggerYamlToConfig(diggerYaml *DiggerConfigYaml) (*DiggerConfig, gra
292292
diggerConfig.MentionDriftedProjectsInPR = false
293293
}
294294

295+
if diggerYaml.GenerateProjectsConfig != nil {
296+
diggerConfig.DriftExcludePatterns = diggerYaml.GenerateProjectsConfig.DriftExcludePatterns
297+
diggerConfig.DriftIncludePatterns = diggerYaml.GenerateProjectsConfig.DriftIncludePatterns
298+
}
299+
295300
if diggerYaml.PrLocks != nil {
296301
diggerConfig.PrLocks = *diggerYaml.PrLocks
297302
} else {

libs/digger_config/yaml.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ type GenerateProjectsConfigYaml struct {
159159
TerragruntParsingConfig *TerragruntParsingConfig `yaml:"terragrunt_parsing,omitempty"`
160160
AwsRoleToAssume *AssumeRoleForProjectConfig `yaml:"aws_role_to_assume,omitempty"`
161161
AwsCognitoOidcConfig *AwsCognitoOidcConfig `yaml:"aws_cognito_oidc,omitempty"`
162+
DriftExcludePatterns []string `yaml:"drift_exclude_patterns,omitempty"`
163+
DriftIncludePatterns []string `yaml:"drift_include_patterns,omitempty"`
162164
}
163165

164166
type TerragruntParsingConfig struct {

0 commit comments

Comments
 (0)