Skip to content

Commit

Permalink
fix matching logic (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbowron authored Jun 4, 2024
1 parent dd52391 commit 661fb29
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions internal/terraform/cmd_drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,39 +99,41 @@ func calculateDrift(path string, matchPatterns []string, skipPatterns []string)
log.Fatalf("Failed to get root modules: %s", err)
}

var matchedModules []string
matchedModules := make(map[string]bool)
for _, module := range modules {
for _, pattern := range matchPatterns {
match, err := doublestar.PathMatch(fmt.Sprintf("**/%s/**", pattern), module)
if err != nil {
log.Fatalf("match pattern error: %s", err)
}
if match {
matchedModules = append(matchedModules, module)
matchedModules[module] = true
}
}
}
var finalModules []string
for _, module := range matchedModules {
for _, pattern := range skipPatterns {
match, err := doublestar.PathMatch(fmt.Sprintf("**/%s/**", pattern), module)
if err != nil {
log.Fatalf("skip pattern error: %s", err)
}
if !match {
finalModules = append(finalModules, module)
if match {
matchedModules[module] = false
}
}
}
var finalModules []string
for module, match := range matchedModules {
if match {
finalModules = append(finalModules, module)
}
}

planCount := len(finalModules)
slog.Debug(
"SEARCH",
slog.Int("moduleCount", len(modules)),
slog.Int("modulesFound", len(modules)),
slog.Any("matchPatterns", matchPatterns),
slog.Int("matchCount", len(matchedModules)),
slog.Any("skipPatterns", skipPatterns),
slog.Int("skipCount", len(matchedModules)-len(finalModules)),
slog.Int("modulesMatched", len(finalModules)),
)
slog.Info("running plans", "planCount", len(finalModules))

Expand Down

0 comments on commit 661fb29

Please sign in to comment.