move some more plugin search path logic to command
Make less to change when we remove the old search path
This commit is contained in:
parent
2749946f5c
commit
66ebff90cd
|
@ -4,12 +4,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
plugin "github.com/hashicorp/go-plugin"
|
plugin "github.com/hashicorp/go-plugin"
|
||||||
tfplugin "github.com/hashicorp/terraform/plugin"
|
tfplugin "github.com/hashicorp/terraform/plugin"
|
||||||
"github.com/hashicorp/terraform/plugin/discovery"
|
"github.com/hashicorp/terraform/plugin/discovery"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
"github.com/kardianos/osext"
|
||||||
)
|
)
|
||||||
|
|
||||||
// multiVersionProviderResolver is an implementation of
|
// multiVersionProviderResolver is an implementation of
|
||||||
|
@ -40,20 +43,43 @@ func (r *multiVersionProviderResolver) ResolveProviders(
|
||||||
return factories, errs
|
return factories, errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// providerPluginSet returns the set of valid providers that were discovered in
|
// the default location for automatically installed plugins
|
||||||
// the defined search paths.
|
func (m *Meta) pluginDir() string {
|
||||||
func (m *Meta) providerPluginSet() discovery.PluginMetaSet {
|
return filepath.Join(m.DataDir(), "plugins", fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH))
|
||||||
var dirs []string
|
}
|
||||||
|
|
||||||
|
// pluginDirs return a list of directories to search for plugins.
|
||||||
|
//
|
||||||
|
// Earlier entries in this slice get priority over later when multiple copies
|
||||||
|
// of the same plugin version are found, but newer versions always override
|
||||||
|
// older versions where both satisfy the provider version constraints.
|
||||||
|
func (m *Meta) pluginDirs() []string {
|
||||||
|
|
||||||
// When searching the following directories, earlier entries get precedence
|
// When searching the following directories, earlier entries get precedence
|
||||||
// if the same plugin version is found twice, but newer versions will
|
// if the same plugin version is found twice, but newer versions will
|
||||||
// always get preference below regardless of where they are coming from.
|
// always get preference below regardless of where they are coming from.
|
||||||
// TODO: Add auto-install dir, default vendor dir and optional override
|
// TODO: Add auto-install dir, default vendor dir and optional override
|
||||||
// vendor dir(s).
|
// vendor dir(s).
|
||||||
dirs = append(dirs, ".")
|
dirs := []string{"."}
|
||||||
dirs = append(dirs, m.GlobalPluginDirs...)
|
|
||||||
|
|
||||||
plugins := discovery.FindPlugins("provider", dirs)
|
// Look in the same directory as the Terraform executable.
|
||||||
|
// If found, this replaces what we found in the config path.
|
||||||
|
exePath, err := osext.Executable()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[ERROR] Error discovering exe directory: %s", err)
|
||||||
|
} else {
|
||||||
|
dirs = append(dirs, filepath.Dir(exePath))
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs = append(dirs, m.pluginDir())
|
||||||
|
dirs = append(dirs, m.GlobalPluginDirs...)
|
||||||
|
return dirs
|
||||||
|
}
|
||||||
|
|
||||||
|
// providerPluginSet returns the set of valid providers that were discovered in
|
||||||
|
// the defined search paths.
|
||||||
|
func (m *Meta) providerPluginSet() discovery.PluginMetaSet {
|
||||||
|
plugins := discovery.FindPlugins("provider", m.pluginDirs())
|
||||||
plugins, _ = plugins.ValidateVersions()
|
plugins, _ = plugins.ValidateVersions()
|
||||||
|
|
||||||
return plugins
|
return plugins
|
||||||
|
@ -81,19 +107,7 @@ func (m *Meta) missingProviders(reqd discovery.PluginRequirements) discovery.Plu
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Meta) provisionerFactories() map[string]terraform.ResourceProvisionerFactory {
|
func (m *Meta) provisionerFactories() map[string]terraform.ResourceProvisionerFactory {
|
||||||
var dirs []string
|
dirs := m.pluginDirs()
|
||||||
|
|
||||||
// When searching the following directories, earlier entries get precedence
|
|
||||||
// if the same plugin version is found twice, but newer versions will
|
|
||||||
// always get preference below regardless of where they are coming from.
|
|
||||||
//
|
|
||||||
// NOTE: Currently we don't use versioning for provisioners, so the
|
|
||||||
// version handling here is just the minimum required to be able to use
|
|
||||||
// the plugin discovery package. All provisioner plugins should always
|
|
||||||
// be versionless, which we treat as version 0.0.0 here.
|
|
||||||
dirs = append(dirs, ".")
|
|
||||||
dirs = append(dirs, m.GlobalPluginDirs...)
|
|
||||||
|
|
||||||
plugins := discovery.FindPlugins("provisioner", dirs)
|
plugins := discovery.FindPlugins("provisioner", dirs)
|
||||||
plugins, _ = plugins.ValidateVersions()
|
plugins, _ = plugins.ValidateVersions()
|
||||||
|
|
||||||
|
|
12
plugins.go
12
plugins.go
|
@ -3,8 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/kardianos/osext"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// globalPluginDirs returns directories that should be searched for
|
// globalPluginDirs returns directories that should be searched for
|
||||||
|
@ -15,16 +13,6 @@ import (
|
||||||
// older versions where both satisfy the provider version constraints.
|
// older versions where both satisfy the provider version constraints.
|
||||||
func globalPluginDirs() []string {
|
func globalPluginDirs() []string {
|
||||||
var ret []string
|
var ret []string
|
||||||
|
|
||||||
// Look in the same directory as the Terraform executable.
|
|
||||||
// If found, this replaces what we found in the config path.
|
|
||||||
exePath, err := osext.Executable()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[ERROR] Error discovering exe directory: %s", err)
|
|
||||||
} else {
|
|
||||||
ret = append(ret, filepath.Dir(exePath))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look in ~/.terraform.d/plugins/ , or its equivalent on non-UNIX
|
// Look in ~/.terraform.d/plugins/ , or its equivalent on non-UNIX
|
||||||
dir, err := ConfigDir()
|
dir, err := ConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue