Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discover plugins/providers #190

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package main

import (
"os"
"os/exec"
"path/filepath"
"strings"
"log"

"github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/terraform/rpc"
Expand Down Expand Up @@ -45,6 +48,43 @@ func init() {
"remote-exec": "terraform-provisioner-remote-exec",
"file": "terraform-provisioner-file",
}

if len(os.Getenv("TF_CUSTOM")) == 0 {
return
}

exePath, err := osext.Executable()
if err != nil {
return
}
path := filepath.Dir(exePath)

GetCustom(path + "/terraform-provider-*", BuiltinConfig.Providers)
GetCustom(path + "/terraform-provisioner-*", BuiltinConfig.Provisioners)

// log.Printf("[DEBUG] Provisioners: %v\n", BuiltinConfig.Provisioners )
// log.Printf("[DEBUG] Providers: %v\n", BuiltinConfig.Providers )
}

func GetCustom(glob_pattern string, builtin_items map[string]string) {

matches, err := filepath.Glob(glob_pattern)
if err != nil {
return
}

for _, match := range(matches) {
path_toks := strings.Split(match, "/")
provider_file := path_toks[len(path_toks) - 1]
provider_name_toks := strings.SplitN(provider_file, "-", 3)
provider_name := provider_name_toks[len(provider_name_toks)-1]
_, found := builtin_items[provider_name]
if !found {
log.Printf("[DEBUG] Found %s %s with filename %s.\n",
provider_name_toks[1], provider_name, provider_file)
builtin_items[provider_name] = provider_file
}
}
}

// LoadConfig loads the CLI configuration from ".terraformrc" files.
Expand Down