diff --git a/command/init_test.go b/command/init_test.go index f41f44f4e..ca007e24c 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/hashicorp/terraform/helper/copy" + "github.com/hashicorp/terraform/plugin/discovery" "github.com/mitchellh/cli" ) @@ -620,6 +621,40 @@ func TestInit_getProviderMissing(t *testing.T) { } } +func TestInit_getProviderHaveLegacyVersion(t *testing.T) { + // Create a temporary working directory that is empty + td := tempDir(t) + copy.CopyDir(testFixturePath("init-providers-lock"), td) + defer os.RemoveAll(td) + defer testChdir(t, td)() + + if err := ioutil.WriteFile("terraform-provider-test", []byte("provider bin"), 0755); err != nil { + t.Fatal(err) + } + + // provider test has a version constraint in the config, which should + // trigger the getProvider error below. + ui := new(cli.MockUi) + c := &InitCommand{ + Meta: Meta{ + testingOverrides: metaOverridesForProvider(testProvider()), + Ui: ui, + }, + getProvider: func(dst, provider string, req discovery.Constraints, protoVersion uint) error { + return fmt.Errorf("EXPECTED PROVIDER ERROR %s", provider) + }, + } + + args := []string{} + if code := c.Run(args); code == 0 { + t.Fatalf("expceted error, got output: \n%s", ui.OutputWriter.String()) + } + + if !strings.Contains(ui.ErrorWriter.String(), "EXPECTED PROVIDER ERROR test") { + t.Fatalf("unexpected error output: %s", ui.ErrorWriter) + } +} + func TestInit_providerLockFile(t *testing.T) { // Create a temporary working directory that is empty td := tempDir(t) diff --git a/command/plugins.go b/command/plugins.go index 9539ef51d..42d224ded 100644 --- a/command/plugins.go +++ b/command/plugins.go @@ -108,6 +108,10 @@ func (m *Meta) providerPluginSet() discovery.PluginMetaSet { plugins := discovery.FindPlugins("provider", m.pluginDirs()) plugins, _ = plugins.ValidateVersions() + for p := range plugins { + log.Printf("[DEBUG] found valid plugin: %q", p.Name) + } + return plugins } @@ -121,10 +125,14 @@ func (m *Meta) providerResolver() terraform.ResourceProviderResolver { func (m *Meta) missingPlugins(avail discovery.PluginMetaSet, reqd discovery.PluginRequirements) discovery.PluginRequirements { missing := make(discovery.PluginRequirements) + for n, r := range reqd { + log.Printf("[DEBUG] plugin requirements: %q=%q", n, r.Versions) + } + candidates := avail.ConstrainVersions(reqd) for name, versionSet := range reqd { - if metas := candidates[name]; metas == nil { + if metas := candidates[name]; metas.Count() == 0 { missing[name] = versionSet } }