Merge pull request #15804 from hashicorp/plugin-transparency

plugin: Display version + source when initializing plugins
This commit is contained in:
Radek Simko 2017-08-15 19:43:50 +02:00 committed by GitHub
commit 82c6caa666
3 changed files with 19 additions and 1 deletions

View File

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

View File

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

View File

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