Merge pull request #15769 from hashicorp/jbardin/discovery-paths

load legacy plugin paths
This commit is contained in:
James Bardin 2017-08-09 17:54:59 -04:00 committed by GitHub
commit 5bcc1bae59
4 changed files with 60 additions and 0 deletions

View File

@ -645,6 +645,49 @@ func TestInit_findVendoredProviders(t *testing.T) {
}
}
// make sure we can locate providers defined in the legacy rc file
func TestInit_rcProviders(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
configDirName := "init-legacy-rc"
copy.CopyDir(testFixturePath(configDirName), filepath.Join(td, configDirName))
defer os.RemoveAll(td)
defer testChdir(t, td)()
pluginDir := filepath.Join(td, "custom")
pluginPath := filepath.Join(pluginDir, "terraform-provider-legacy")
ui := new(cli.MockUi)
m := Meta{
Ui: ui,
PluginOverrides: &PluginOverrides{
Providers: map[string]string{
"legacy": pluginPath,
},
},
}
c := &InitCommand{
Meta: m,
providerInstaller: &mockProviderInstaller{},
}
// make our plugin paths
if err := os.MkdirAll(pluginDir, 0755); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(pluginPath, []byte("test bin"), 0755); err != nil {
t.Fatal(err)
}
args := []string{configDirName}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
}
func TestInit_getUpgradePlugins(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)

View File

@ -172,6 +172,12 @@ func (m *Meta) pluginDirs(includeAutoInstalled bool) []string {
// the defined search paths.
func (m *Meta) providerPluginSet() discovery.PluginMetaSet {
plugins := discovery.FindPlugins("provider", m.pluginDirs(true))
// Add providers defined in the legacy .terraformrc,
if m.PluginOverrides != nil {
plugins = plugins.OverridePaths(m.PluginOverrides.Providers)
}
plugins, _ = plugins.ValidateVersions()
for p := range plugins {
@ -198,6 +204,12 @@ func (m *Meta) providerPluginAutoInstalledSet() discovery.PluginMetaSet {
// in all locations *except* the auto-install directory.
func (m *Meta) providerPluginManuallyInstalledSet() discovery.PluginMetaSet {
plugins := discovery.FindPlugins("provider", m.pluginDirs(false))
// Add providers defined in the legacy .terraformrc,
if m.PluginOverrides != nil {
plugins = plugins.OverridePaths(m.PluginOverrides.Providers)
}
plugins, _ = plugins.ValidateVersions()
for p := range plugins {

View File

@ -0,0 +1 @@
provider "legacy" {}

View File

@ -1,8 +1,10 @@
package main
import (
"fmt"
"log"
"path/filepath"
"runtime"
)
// globalPluginDirs returns directories that should be searched for
@ -18,7 +20,9 @@ func globalPluginDirs() []string {
if err != nil {
log.Printf("[ERROR] Error finding global config directory: %s", err)
} else {
machineDir := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
ret = append(ret, filepath.Join(dir, "plugins"))
ret = append(ret, filepath.Join(dir, "plugins", machineDir))
}
return ret