Skip to content

Commit

Permalink
tenable#365 loop through parent to create proper path
Browse files Browse the repository at this point in the history
  • Loading branch information
salexpdx committed Oct 30, 2020
1 parent d7bc4aa commit 89b06f6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/iac-providers/terraform/v12/load-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,20 @@ func (*TfV12) LoadIacDir(absRootDir string) (allResourcesConfig output.AllResour
// using *configs.ModuleRequest.Path field
pathArr := strings.Split(req.Path.String(), ".")
pathArr = pathArr[:len(pathArr)-1]
pathToModule = filepath.Join(absRootDir, filepath.Join(pathArr...), req.SourceAddr)
zap.S().Debugf("processing local module %q", req.SourceAddr)
// As long as parent is not nil, then we are in a child module.
parent := req.Parent
// start module path list with the last element, we will be prepending
// our way through the parents and then finally adding our absRootDir
// as the first element in the list.
modulePathList := []string{req.SourceAddr}
for parent != nil {
modulePathList = append([]string{parent.SourceAddr}, modulePathList...)
parent = parent.Parent
}
modulePathList = append([]string{absRootDir}, modulePathList...)
pathToModule = filepath.Join(modulePathList...)
zap.S().Infof("processing local module %v in directory %v", req.Path.String(), pathToModule)
} else {
// temp dir to download the remote repo
tempDir := filepath.Join(os.TempDir(), utils.GenRandomString(6))
Expand Down

0 comments on commit 89b06f6

Please sign in to comment.