From 9c2fe3456ba3d31966483a6cf36befa5bc990e2b Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 20 Jun 2017 11:25:41 -0700 Subject: [PATCH] command: purge unused plugins as a side effect of plugin installation Previously we only did this when _upgrading_, but that's unnecessarily specific and confusing since e.g. plugins can get upgraded implicitly by constraint changes, which would not then trigger the purge process. Instead, we'll assume that the user is able to easily re-download plugins that were purged here, or if they need more specific guarantees they will manage manually a plugin directory and disable the auto-install behavior using `-plugin-dir`. --- command/init.go | 2 +- command/init_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/command/init.go b/command/init.go index 2ab70c3960..de8b4f2454 100644 --- a/command/init.go +++ b/command/init.go @@ -302,7 +302,7 @@ func (c *InitCommand) getProviders(path string, state *terraform.State, upgrade return err } - if upgrade { + { // Purge any auto-installed plugins that aren't being used. purged, err := c.providerInstaller.PurgeUnused(chosen) if err != nil { diff --git a/command/init_test.go b/command/init_test.go index bf1d0dfca1..069f546769 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -479,6 +479,10 @@ func TestInit_getProvider(t *testing.T) { t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) } + if !installer.PurgeUnusedCalled { + t.Errorf("init didn't purge providers, but should have") + } + // check that we got the providers for our config exactPath := filepath.Join(c.pluginDir(), installer.FileName("exact", "1.2.3")) if _, err := os.Stat(exactPath); os.IsNotExist(err) {