Skip to content

Commit 5ae8348

Browse files
authored
add flag to ignore all external directories per project (#1851)
* add flag to ignore all external directories per project
1 parent c9a0625 commit 5ae8348

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

libs/digger_config/digger_config.go

+5
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,11 @@ func hydrateDiggerConfigYamlWithTerragrunt(configYaml *DiggerConfigYaml, parsing
562562
// normalize paths
563563
projectDir := path.Join(pathPrefix, atlantisProject.Dir)
564564
atlantisProject.Autoplan.WhenModified, err = GetPatternsRelativeToRepo(projectDir, atlantisProject.Autoplan.WhenModified)
565+
566+
if parsingConfig.TriggerProjectsFromDirOnly {
567+
atlantisProject.Autoplan.WhenModified, err = FilterPathsOutsideOfProjectPath(projectDir, atlantisProject.Autoplan.WhenModified)
568+
}
569+
565570
if err != nil {
566571
return fmt.Errorf("could not normalize patterns: %v", err)
567572
}

libs/digger_config/utils.go

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66
"path"
77
"path/filepath"
8+
"strings"
89
)
910

1011
func GetPatternsRelativeToRepo(projectPath string, patterns []string) ([]string, error) {
@@ -15,6 +16,16 @@ func GetPatternsRelativeToRepo(projectPath string, patterns []string) ([]string,
1516
return res, nil
1617
}
1718

19+
func FilterPathsOutsideOfProjectPath(projectPath string, patterns []string) ([]string, error) {
20+
res := make([]string, 0)
21+
for _, pattern := range patterns {
22+
if strings.HasPrefix(pattern, projectPath) {
23+
res = append(res, pattern)
24+
}
25+
}
26+
return res, nil
27+
}
28+
1829
func NormalizeFileName(fileName string) string {
1930
res, err := filepath.Abs(path.Join("/", fileName))
2031
if err != nil {

libs/digger_config/utils_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ func TestGetPatternsRelativeToRepo(t *testing.T) {
4545
assert.Equal(t, "myProject/terraform/environments/devel/*.hcl", res[0])
4646

4747
}
48+
49+
func TestFilterPathsOutsideOfProjectPath(t *testing.T) {
50+
projectDir := "staging/aws/us-east-1/k8s"
51+
includePatterns := []string{"staging/aws/us-east-1/k8s/*.hcl", "staging/terragrunt-root.hcl vpc/*.tf*", "staging/aws/us-east-1/aws_region.tfvars", "staging/aws/aws_assume_role_arn.tfvars", "staging/aws/us-east-1/k8s/*.tf*"}
52+
res, _ := FilterPathsOutsideOfProjectPath(projectDir, includePatterns)
53+
assert.Equal(t, 2, len(res))
54+
assert.Equal(t, "staging/aws/us-east-1/k8s/*.hcl", res[0])
55+
assert.Equal(t, "staging/aws/us-east-1/k8s/*.tf*", res[1])
56+
57+
}

libs/digger_config/yaml.go

+19-18
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,25 @@ type GenerateProjectsConfigYaml struct {
137137
}
138138

139139
type TerragruntParsingConfig struct {
140-
GitRoot *string `yaml:"gitRoot,omitempty"`
141-
AutoPlan bool `yaml:"autoPlan"`
142-
AutoMerge bool `yaml:"autoMerge"`
143-
IgnoreParentTerragrunt *bool `yaml:"ignoreParentTerragrunt,omitempty"`
144-
CreateParentProject bool `yaml:"createParentProject"`
145-
IgnoreDependencyBlocks bool `yaml:"ignoreDependencyBlocks"`
146-
IgnoreIncludeBlocks bool `yaml:"ignoreIncludeBlocks"`
147-
Parallel *bool `yaml:"parallel,omitempty"`
148-
CreateWorkspace bool `yaml:"createWorkspace"`
149-
CreateProjectName bool `yaml:"createProjectName"`
150-
DefaultTerraformVersion string `yaml:"defaultTerraformVersion"`
151-
DefaultWorkflow string `yaml:"defaultWorkflow"`
152-
FilterPath string `yaml:"filterPath"`
153-
OutputPath string `yaml:"outputPath"`
154-
PreserveWorkflows *bool `yaml:"preserveWorkflows,omitempty"`
155-
PreserveProjects bool `yaml:"preserveProjects"`
156-
CascadeDependencies *bool `yaml:"cascadeDependencies,omitempty"`
157-
DefaultApplyRequirements []string `yaml:"defaultApplyRequirements"`
140+
GitRoot *string `yaml:"gitRoot,omitempty"`
141+
AutoPlan bool `yaml:"autoPlan"`
142+
AutoMerge bool `yaml:"autoMerge"`
143+
IgnoreParentTerragrunt *bool `yaml:"ignoreParentTerragrunt,omitempty"`
144+
CreateParentProject bool `yaml:"createParentProject"`
145+
IgnoreDependencyBlocks bool `yaml:"ignoreDependencyBlocks"`
146+
IgnoreIncludeBlocks bool `yaml:"ignoreIncludeBlocks"`
147+
TriggerProjectsFromDirOnly bool `yaml:"triggerProjectsFromDirOnly"`
148+
Parallel *bool `yaml:"parallel,omitempty"`
149+
CreateWorkspace bool `yaml:"createWorkspace"`
150+
CreateProjectName bool `yaml:"createProjectName"`
151+
DefaultTerraformVersion string `yaml:"defaultTerraformVersion"`
152+
DefaultWorkflow string `yaml:"defaultWorkflow"`
153+
FilterPath string `yaml:"filterPath"`
154+
OutputPath string `yaml:"outputPath"`
155+
PreserveWorkflows *bool `yaml:"preserveWorkflows,omitempty"`
156+
PreserveProjects bool `yaml:"preserveProjects"`
157+
CascadeDependencies *bool `yaml:"cascadeDependencies,omitempty"`
158+
DefaultApplyRequirements []string `yaml:"defaultApplyRequirements"`
158159
//NumExecutors int64 `yaml:"numExecutors"`
159160
ProjectHclFiles []string `yaml:"projectHclFiles"`
160161
CreateHclProjectChilds bool `yaml:"createHclProjectChilds"`

0 commit comments

Comments
 (0)