Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag to ignore all external directories per project #1851

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libs/digger_config/digger_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ func hydrateDiggerConfigYamlWithTerragrunt(configYaml *DiggerConfigYaml, parsing
// normalize paths
projectDir := path.Join(pathPrefix, atlantisProject.Dir)
atlantisProject.Autoplan.WhenModified, err = GetPatternsRelativeToRepo(projectDir, atlantisProject.Autoplan.WhenModified)

if parsingConfig.TriggerProjectsFromDirOnly {
atlantisProject.Autoplan.WhenModified, err = FilterPathsOutsideOfProjectPath(projectDir, atlantisProject.Autoplan.WhenModified)
}

motatoes marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("could not normalize patterns: %v", err)
}
Expand Down
11 changes: 11 additions & 0 deletions libs/digger_config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"path"
"path/filepath"
"strings"
)

func GetPatternsRelativeToRepo(projectPath string, patterns []string) ([]string, error) {
Expand All @@ -15,6 +16,16 @@ func GetPatternsRelativeToRepo(projectPath string, patterns []string) ([]string,
return res, nil
}

func FilterPathsOutsideOfProjectPath(projectPath string, patterns []string) ([]string, error) {
res := make([]string, 0)
for _, pattern := range patterns {
if strings.HasPrefix(pattern, projectPath) {
res = append(res, pattern)
}
}
return res, nil
}

func NormalizeFileName(fileName string) string {
res, err := filepath.Abs(path.Join("/", fileName))
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions libs/digger_config/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ func TestGetPatternsRelativeToRepo(t *testing.T) {
assert.Equal(t, "myProject/terraform/environments/devel/*.hcl", res[0])

}

func TestFilterPathsOutsideOfProjectPath(t *testing.T) {
projectDir := "staging/aws/us-east-1/k8s"
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*"}
res, _ := FilterPathsOutsideOfProjectPath(projectDir, includePatterns)
assert.Equal(t, 2, len(res))
assert.Equal(t, "staging/aws/us-east-1/k8s/*.hcl", res[0])
assert.Equal(t, "staging/aws/us-east-1/k8s/*.tf*", res[1])

}
motatoes marked this conversation as resolved.
Show resolved Hide resolved
37 changes: 19 additions & 18 deletions libs/digger_config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,25 @@ type GenerateProjectsConfigYaml struct {
}

type TerragruntParsingConfig struct {
GitRoot *string `yaml:"gitRoot,omitempty"`
AutoPlan bool `yaml:"autoPlan"`
AutoMerge bool `yaml:"autoMerge"`
IgnoreParentTerragrunt *bool `yaml:"ignoreParentTerragrunt,omitempty"`
CreateParentProject bool `yaml:"createParentProject"`
IgnoreDependencyBlocks bool `yaml:"ignoreDependencyBlocks"`
IgnoreIncludeBlocks bool `yaml:"ignoreIncludeBlocks"`
Parallel *bool `yaml:"parallel,omitempty"`
CreateWorkspace bool `yaml:"createWorkspace"`
CreateProjectName bool `yaml:"createProjectName"`
DefaultTerraformVersion string `yaml:"defaultTerraformVersion"`
DefaultWorkflow string `yaml:"defaultWorkflow"`
FilterPath string `yaml:"filterPath"`
OutputPath string `yaml:"outputPath"`
PreserveWorkflows *bool `yaml:"preserveWorkflows,omitempty"`
PreserveProjects bool `yaml:"preserveProjects"`
CascadeDependencies *bool `yaml:"cascadeDependencies,omitempty"`
DefaultApplyRequirements []string `yaml:"defaultApplyRequirements"`
GitRoot *string `yaml:"gitRoot,omitempty"`
AutoPlan bool `yaml:"autoPlan"`
AutoMerge bool `yaml:"autoMerge"`
IgnoreParentTerragrunt *bool `yaml:"ignoreParentTerragrunt,omitempty"`
CreateParentProject bool `yaml:"createParentProject"`
IgnoreDependencyBlocks bool `yaml:"ignoreDependencyBlocks"`
IgnoreIncludeBlocks bool `yaml:"ignoreIncludeBlocks"`
TriggerProjectsFromDirOnly bool `yaml:"triggerProjectsFromDirOnly"`
Parallel *bool `yaml:"parallel,omitempty"`
CreateWorkspace bool `yaml:"createWorkspace"`
CreateProjectName bool `yaml:"createProjectName"`
DefaultTerraformVersion string `yaml:"defaultTerraformVersion"`
DefaultWorkflow string `yaml:"defaultWorkflow"`
FilterPath string `yaml:"filterPath"`
OutputPath string `yaml:"outputPath"`
PreserveWorkflows *bool `yaml:"preserveWorkflows,omitempty"`
PreserveProjects bool `yaml:"preserveProjects"`
CascadeDependencies *bool `yaml:"cascadeDependencies,omitempty"`
DefaultApplyRequirements []string `yaml:"defaultApplyRequirements"`
//NumExecutors int64 `yaml:"numExecutors"`
ProjectHclFiles []string `yaml:"projectHclFiles"`
CreateHclProjectChilds bool `yaml:"createHclProjectChilds"`
Expand Down
Loading