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`.
This commit is contained in:
Martin Atkins 2017-06-20 11:25:41 -07:00
parent d48dcbb4a5
commit 9c2fe3456b
2 changed files with 5 additions and 1 deletions

View File

@ -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 {

View File

@ -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) {