From 41ab0aef7a0fe030e84018973a64135b11abcd70 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 9 Aug 2017 10:34:11 -0400 Subject: [PATCH 1/4] Add missing OS_ARCH dir to global plugin paths When the global directory was added, the discovery system still attempted to search for OS_ARCH subdirectories. It has since been changed only search explicit paths. --- plugins.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins.go b/plugins.go index bf23978062..668c516542 100644 --- a/plugins.go +++ b/plugins.go @@ -1,8 +1,10 @@ package main import ( + "fmt" "log" "path/filepath" + "runtime" ) // globalPluginDirs returns directories that should be searched for @@ -18,7 +20,8 @@ func globalPluginDirs() []string { if err != nil { log.Printf("[ERROR] Error finding global config directory: %s", err) } else { - ret = append(ret, filepath.Join(dir, "plugins")) + machineDir := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH) + ret = append(ret, filepath.Join(dir, "plugins", machineDir)) } return ret From fa20d43d80fd56b19c16af63f38be5da1ef2f0eb Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 9 Aug 2017 11:13:54 -0400 Subject: [PATCH 2/4] test loading of Meta.PluginOverrides These are currently being skipped in discovery --- command/init_test.go | 43 ++++++++++++++++++++ command/test-fixtures/init-legacy-rc/main.tf | 1 + 2 files changed, 44 insertions(+) create mode 100644 command/test-fixtures/init-legacy-rc/main.tf diff --git a/command/init_test.go b/command/init_test.go index ebfa397f1a..ef192b7e54 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -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) diff --git a/command/test-fixtures/init-legacy-rc/main.tf b/command/test-fixtures/init-legacy-rc/main.tf new file mode 100644 index 0000000000..4b04a89e43 --- /dev/null +++ b/command/test-fixtures/init-legacy-rc/main.tf @@ -0,0 +1 @@ +provider "legacy" {} From 54998933f5ae0a60389b32018f9b55b01d2072c1 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 9 Aug 2017 11:14:33 -0400 Subject: [PATCH 3/4] load Meta.PluginOverrides in dicovery Make sure the override paths from the legacy rc file are loaded for discovery. --- command/plugins.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/command/plugins.go b/command/plugins.go index ca94f07b93..ce26b0f855 100644 --- a/command/plugins.go +++ b/command/plugins.go @@ -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 { From 52dbf94834cb970b510f2fba853a5b49ad9b1a46 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 9 Aug 2017 17:46:49 -0400 Subject: [PATCH 4/4] keep .terraform.d/plugins for discovery --- plugins.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins.go b/plugins.go index 668c516542..cf2d542535 100644 --- a/plugins.go +++ b/plugins.go @@ -21,6 +21,7 @@ func globalPluginDirs() []string { 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)) }