Skip to content

Commit

Permalink
Added Support for Terraform 0.14 and 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
juliosueiras committed May 13, 2021
1 parent 8d09c4c commit b0a5e4c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tfstructs/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"strings"

internalPlugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/terraform/plugin/discovery"
"github.com/hashicorp/terraform/providers"
Expand Down Expand Up @@ -210,6 +212,48 @@ func pluginDirs(targetDir string) ([]string, error) {
}
}

if _, err := os.Stat(filepath.Join(dir, ".terraform.lock.hcl")); err == nil {
file, _ := ioutil.ReadFile(filepath.Join(dir, ".terraform.lock.hcl"))
lockFile, _ := hclsyntax.ParseConfig(file, ".terraform.lock.hcl", hcl.Pos{
Column: 1,
Line: 1,
})

parsedLock, _ := lockFile.Body.Content(&hcl.BodySchema{
Blocks: []hcl.BlockHeaderSchema{
{
LabelNames: []string{"provider"},
Type: "provider",
},
},
})

for _, provider := range parsedLock.Blocks {
name := []string{
dir,
".terraform",
"providers",
}
name = append(name, strings.Split(provider.Labels[0], "/")...)

vars, _ := provider.Body.JustAttributes()
version := ""
for _, i := range vars {
if i.Name == "version" {
tempVersion, _ := i.Expr.Value(nil)

version = tempVersion.AsString()
}
}

result := append(name, version, arch)

if _, err := os.Stat(filepath.Join(result...)); err == nil {
dirs = append(dirs, filepath.Join(result...))
}
}
}

break
}

Expand Down

0 comments on commit b0a5e4c

Please sign in to comment.