Skip to content

Commit

Permalink
fix: terragrunt provider has a 1-1 relationship with a project
Browse files Browse the repository at this point in the history
  • Loading branch information
hugorut committed Jan 26, 2024
1 parent 3f3fa55 commit 8fe02b9
Showing 1 changed file with 3 additions and 68 deletions.
71 changes: 3 additions & 68 deletions internal/providers/terraform/terragrunt_hcl_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,25 +419,10 @@ func (p *TerragruntHCLProvider) prepWorkingDirs() ([]*terragruntWorkingDirInfo,
Parallelism: 1,
}

terragruntConfigFiles, err := tgconfig.FindConfigFilesInPath(terragruntOptions.WorkingDir, terragruntOptions)
if err != nil {
return nil, err
}

// Filter these config files against the exclude paths so Terragrunt doesn't even try to evaluate them
terragruntConfigFiles = p.filterExcludedPaths(terragruntConfigFiles)

var filtered []string
for _, file := range terragruntConfigFiles {
if !hcl.IsParentTerragruntConfig(file, terragruntConfigFiles) {
filtered = append(filtered, file)
}
}

terragruntConfigFiles = filtered

howThesePathsWereFound := fmt.Sprintf("Terragrunt config file found in a subdirectory of %s", terragruntOptions.WorkingDir)
s, err := createStackForTerragruntConfigPaths(terragruntOptions.WorkingDir, terragruntConfigFiles, terragruntOptions, howThesePathsWereFound)
s, err := createStackForTerragruntConfigPaths(terragruntOptions.WorkingDir, []string{
terragruntConfigPath,
}, terragruntOptions, howThesePathsWereFound)
if err != nil {
return nil, err
}
Expand All @@ -460,25 +445,6 @@ func (p *TerragruntHCLProvider) prepWorkingDirs() ([]*terragruntWorkingDirInfo,
return workingDirsToEstimate, nil
}

func (p *TerragruntHCLProvider) filterExcludedPaths(paths []string) []string {
excludedPaths := p.excludedPaths
excludedPaths = append(excludedPaths, config.InfracostDir)

isSkipped := buildExcludedPathsMatcher(p.Path.Path, excludedPaths)

var filteredPaths []string

for _, path := range paths {
if !isSkipped(path) {
filteredPaths = append(filteredPaths, path)
} else {
p.logger.Debug().Msgf("skipping path %s as it is marked as excluded by --exclude-path", path)
}
}

return filteredPaths
}

// runTerragrunt evaluates a Terragrunt directory with the given opts. This method is called from the
// Terragrunt internal libs as part of the Terraform project evaluation. runTerragrunt is called with for all of the folders
// in a Terragrunt project. Folders that have outputs that are used by other folders are evaluated first.
Expand Down Expand Up @@ -695,37 +661,6 @@ func generateConfig(terragruntConfig *tgconfig.TerragruntConfig, opts *options.T
return nil
}

func buildExcludedPathsMatcher(fullPath string, excludedDirs []string) func(string) bool {
var excludedMatches []string

for _, dir := range excludedDirs {
var absoluteDir string

if filepath.IsAbs(dir) {
absoluteDir = dir
} else {
absoluteDir, _ = filepath.Abs(filepath.Join(fullPath, dir))
}

globs, err := filepath.Glob(absoluteDir)
if err == nil {
excludedMatches = append(excludedMatches, globs...)
}
}

return func(dir string) bool {
absoluteDir, _ := filepath.Abs(dir)

for _, match := range excludedMatches {
if strings.HasPrefix(absoluteDir, match) {
return true
}
}

return false
}
}

func convertToCtyWithJson(val interface{}) (cty.Value, error) {
jsonBytes, err := json.Marshal(val)
if err != nil {
Expand Down

0 comments on commit 8fe02b9

Please sign in to comment.