From 28b33c9299f2a60f04f158deb749425ba078a382 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 14 Aug 2017 13:32:48 +0200 Subject: [PATCH] plugin: Display version + source when initializing plugins --- command/init.go | 7 ++++++- plugin/discovery/get.go | 8 ++++++++ plugin/discovery/get_test.go | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/command/init.go b/command/init.go index 427a8ce52..403ca245b 100644 --- a/command/init.go +++ b/command/init.go @@ -75,6 +75,7 @@ func (c *InitCommand) Run(args []string) int { Dir: c.pluginDir(), PluginProtocolVersion: plugin.Handshake.ProtocolVersion, SkipVerify: !flagVerifyPlugins, + Ui: c.Ui, } } @@ -310,8 +311,12 @@ func (c *InitCommand) getProviders(path string, state *terraform.State, upgrade var errs error if c.getPlugins { + if len(missing) > 0 { + c.Ui.Output(fmt.Sprintf(" - Checking for available provider plugins on %s...", + discovery.GetReleaseHost())) + } + for provider, reqd := range missing { - c.Ui.Output(fmt.Sprintf("- Downloading plugin for provider %q...", provider)) _, err := c.providerInstaller.Get(provider, reqd.Versions) if err != nil { diff --git a/plugin/discovery/get.go b/plugin/discovery/get.go index 241b5cb3b..64d2b695e 100644 --- a/plugin/discovery/get.go +++ b/plugin/discovery/get.go @@ -16,6 +16,7 @@ import ( cleanhttp "github.com/hashicorp/go-cleanhttp" getter "github.com/hashicorp/go-getter" multierror "github.com/hashicorp/go-multierror" + "github.com/mitchellh/cli" ) // Releases are located by parsing the html listing from releases.hashicorp.com. @@ -58,6 +59,8 @@ type ProviderInstaller struct { // Skip checksum and signature verification SkipVerify bool + + Ui cli.Ui // Ui for output } // Get is part of an implementation of type Installer, and attempts to download @@ -116,6 +119,7 @@ func (i *ProviderInstaller) Get(provider string, req Constraints) (PluginMeta, e log.Printf("[DEBUG] fetching provider info for %s version %s", provider, v) if checkPlugin(url, i.PluginProtocolVersion) { + i.Ui.Info(fmt.Sprintf("- Downloading plugin for provider %q (%s)...", provider, v.String())) log.Printf("[DEBUG] getting provider %q version %q at %s", provider, v, url) err := getter.Get(i.Dir, url) if err != nil { @@ -422,3 +426,7 @@ func getFile(url string) ([]byte, error) { } return data, nil } + +func GetReleaseHost() string { + return releaseHost +} diff --git a/plugin/discovery/get_test.go b/plugin/discovery/get_test.go index 16ba697cd..65b2497aa 100644 --- a/plugin/discovery/get_test.go +++ b/plugin/discovery/get_test.go @@ -13,6 +13,8 @@ import ( "regexp" "strings" "testing" + + "github.com/mitchellh/cli" ) const testProviderFile = "test provider binary" @@ -149,6 +151,7 @@ func TestProviderInstallerGet(t *testing.T) { Dir: tmpDir, PluginProtocolVersion: 5, SkipVerify: true, + Ui: cli.NewMockUi(), } _, err = i.Get("test", AllVersions) if err != ErrorNoVersionCompatible { @@ -159,6 +162,7 @@ func TestProviderInstallerGet(t *testing.T) { Dir: tmpDir, PluginProtocolVersion: 3, SkipVerify: true, + Ui: cli.NewMockUi(), } { @@ -230,6 +234,7 @@ func TestProviderInstallerPurgeUnused(t *testing.T) { Dir: tmpDir, PluginProtocolVersion: 3, SkipVerify: true, + Ui: cli.NewMockUi(), } purged, err := i.PurgeUnused(map[string]PluginMeta{ "test": PluginMeta{