Skip to content

Commit

Permalink
revert filterPaths modification
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes committed Dec 13, 2024
1 parent 1ca2067 commit 334bbdf
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 36 deletions.
1 change: 1 addition & 0 deletions backend/controllers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
diggerYmlStr, ghService, config, projectsGraph, _, _, changedFiles, err := getDiggerConfigForPR(gh, organisationId, prLabelsStr, installationId, repoFullName, repoOwner, repoName, cloneURL, prNumber)
if err != nil {
log.Printf("getDiggerConfigForPR error: %v", err)
commentReporterManager.UpdateComment(fmt.Sprintf(":x: Error loading digger config: %v", err))
return fmt.Errorf("error getting digger config")
}

Expand Down
4 changes: 2 additions & 2 deletions libs/digger_config/digger_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func HandleYamlProjectGeneration(config *DiggerConfigYaml, terraformDir string,
CreateProjectName: true,
DefaultWorkflow: workflow,
WorkflowFile: b.WorkflowFile,
FilterPaths: []string{path.Join(terraformDir, *b.RootDir)},
FilterPath: path.Join(terraformDir, *b.RootDir),
AwsRoleToAssume: b.AwsRoleToAssume,
AwsCognitoOidcConfig: b.AwsCognitoOidcConfig,
}
Expand Down Expand Up @@ -522,7 +522,7 @@ func hydrateDiggerConfigYamlWithTerragrunt(configYaml *DiggerConfigYaml, parsing
projectExternalChilds,
parsingConfig.AutoMerge,
parallel,
parsingConfig.FilterPaths,
parsingConfig.FilterPath,
parsingConfig.CreateHclProjectChilds,
ignoreParentTerragrunt,
parsingConfig.IgnoreDependencyBlocks,
Expand Down
20 changes: 8 additions & 12 deletions libs/digger_config/terragrunt/atlantis/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func createHclProject(defaultWorkflow string, defaultApplyRequirements []string,
}

// Finds the absolute paths of all terragrunt.hcl files
func getAllTerragruntFiles(filterPaths []string, projectHclFiles []string, path string) ([]string, error) {
func getAllTerragruntFiles(filterPath string, projectHclFiles []string, path string) ([]string, error) {
options, err := options.NewTerragruntOptionsWithConfigPath(path)
if err != nil {
return nil, err
Expand All @@ -610,15 +610,11 @@ func getAllTerragruntFiles(filterPaths []string, projectHclFiles []string, path
workingPaths := []string{path}

// filters are not working (yet) if using project hcl files (which are kind of filters by themselves)
if len(filterPaths) > 0 && len(projectHclFiles) == 0 {
workingPaths = []string{}
for _, filterPath := range filterPaths {
// get all matching folders
theseWorkingPaths, err := filepath.Glob(filterPath)
if err != nil {
return nil, err
}
workingPaths = append(workingPaths, theseWorkingPaths...)
if filterPath != "" && len(projectHclFiles) == 0 {
// get all matching folders
workingPaths, err = filepath.Glob(filterPath)
if err != nil {
return nil, err
}
}

Expand Down Expand Up @@ -682,7 +678,7 @@ func getAllTerragruntProjectHclFiles(projectHclFiles []string, gitRoot string) m
return uniqueHclFileAbsPaths
}

func Parse(gitRoot string, projectHclFiles []string, createHclProjectExternalChilds bool, autoMerge bool, parallel bool, filterPaths []string, createHclProjectChilds bool, ignoreParentTerragrunt bool, ignoreDependencyBlocks bool, cascadeDependencies bool, defaultWorkflow string, defaultApplyRequirements []string, autoPlan bool, defaultTerraformVersion string, createProjectName bool, createWorkspace bool, preserveProjects bool, useProjectMarkers bool, executionOrderGroups bool, triggerProjectsFromDirOnly bool) (*AtlantisConfig, map[string][]string, error) {
func Parse(gitRoot string, projectHclFiles []string, createHclProjectExternalChilds bool, autoMerge bool, parallel bool, filterPath string, createHclProjectChilds bool, ignoreParentTerragrunt bool, ignoreDependencyBlocks bool, cascadeDependencies bool, defaultWorkflow string, defaultApplyRequirements []string, autoPlan bool, defaultTerraformVersion string, createProjectName bool, createWorkspace bool, preserveProjects bool, useProjectMarkers bool, executionOrderGroups bool, triggerProjectsFromDirOnly bool) (*AtlantisConfig, map[string][]string, error) {
// Ensure the gitRoot has a trailing slash and is an absolute path
absoluteGitRoot, err := filepath.Abs(gitRoot)
if err != nil {
Expand Down Expand Up @@ -718,7 +714,7 @@ func Parse(gitRoot string, projectHclFiles []string, createHclProjectExternalChi
sem := semaphore.NewWeighted(10)
projectDependenciesMap := sync.Map{}
for _, workingDir := range workingDirs {
terragruntFiles, err := getAllTerragruntFiles(filterPaths, projectHclFiles, workingDir)
terragruntFiles, err := getAllTerragruntFiles(filterPath, projectHclFiles, workingDir)
if err != nil {
return nil, nil, err
}
Expand Down
11 changes: 0 additions & 11 deletions libs/digger_config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"path"
"path/filepath"
"strings"
)

func GetPatternsRelativeToRepo(projectPath string, patterns []string) ([]string, error) {
Expand All @@ -16,16 +15,6 @@ 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: 0 additions & 10 deletions libs/digger_config/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,3 @@ 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])

}
2 changes: 1 addition & 1 deletion libs/digger_config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type TerragruntParsingConfig struct {
CreateProjectName bool `yaml:"createProjectName"`
DefaultTerraformVersion string `yaml:"defaultTerraformVersion"`
DefaultWorkflow string `yaml:"defaultWorkflow"`
FilterPaths []string `yaml:"filterPath"`
FilterPath string `yaml:"filterPath"`
OutputPath string `yaml:"outputPath"`
PreserveWorkflows *bool `yaml:"preserveWorkflows,omitempty"`
PreserveProjects bool `yaml:"preserveProjects"`
Expand Down

0 comments on commit 334bbdf

Please sign in to comment.