Skip to content

Commit

Permalink
fix file paths for terraform config dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Kanchwala authored and Yusuf Kanchwala committed Aug 13, 2020
1 parent ef820ea commit 59203de
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/iac-providers/terraform/v12/load-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
package tfv12

import (
"bytes"
"fmt"
"path/filepath"
"strings"

"github.com/accurics/terrascan/pkg/iac-providers/output"
version "github.com/hashicorp/go-version"
"github.com/hashicorp/hcl/v2"
hclConfigs "github.com/hashicorp/terraform/configs"
"github.com/spf13/afero"
"go.uber.org/zap"

"github.com/accurics/terrascan/pkg/iac-providers/output"
)

var (
Expand Down Expand Up @@ -122,8 +122,8 @@ func (*TfV12) LoadIacDir(absRootDir string) (allResourcesConfig output.AllResour
return allResourcesConfig, fmt.Errorf("failed to create ResourceConfig")
}

// append resource config to list of all resources
// allResourcesConfig = append(allResourcesConfig, resourceConfig)
// trimFilePath
resourceConfig.Source = trimFilePath(resourceConfig.Source, absRootDir)

// append to normalized output
if _, present := allResourcesConfig[resourceConfig.Type]; !present {
Expand All @@ -142,3 +142,10 @@ func (*TfV12) LoadIacDir(absRootDir string) (allResourcesConfig output.AllResour
// successful
return allResourcesConfig, nil
}

// trimFilePath returns relative file path wrt to the base path
func trimFilePath(fullPath, basePath string) string {
basePath = strings.TrimSuffix(basePath, "/")
splits := bytes.Split([]byte(fullPath), []byte(basePath))
return strings.TrimPrefix(string(splits[1]), "/")
}

0 comments on commit 59203de

Please sign in to comment.