diff --git a/command/e2etest/init_test.go b/command/e2etest/init_test.go index cc47d3165f..9fcddbfb72 100644 --- a/command/e2etest/init_test.go +++ b/command/e2etest/init_test.go @@ -73,12 +73,51 @@ func TestInitProvidersInternal(t *testing.T) { t.Errorf("success message is missing from output:\n%s", stdout) } - if strings.Contains(stdout, "Downloading plugin for provider") { + if strings.Contains(stdout, "Installing registry.terraform.io/hashicorp/terraform") { // Shouldn't have downloaded anything with this config, because the // provider is built in. t.Errorf("provider download message appeared in output:\n%s", stdout) } + if strings.Contains(stdout, "Installing terraform.io/builtin/terraform") { + // Shouldn't have downloaded anything with this config, because the + // provider is built in. + t.Errorf("provider download message appeared in output:\n%s", stdout) + } +} + +func TestInitProvidersVendored(t *testing.T) { + t.Parallel() + + // This test will try to reach out to registry.terraform.io as one of the + // possible installation locations for + // registry.terraform.io/hashicorp/null, where it will find that + // versions do exist but will ultimately select the version that is + // vendored due to the version constraint. + skipIfCannotAccessNetwork(t) + + fixturePath := filepath.Join("testdata", "vendored-provider") + tf := e2e.NewBinary(terraformBin, fixturePath) + defer tf.Close() + + stdout, stderr, err := tf.Run("init") + if err != nil { + t.Errorf("unexpected error: %s", err) + } + + if stderr != "" { + t.Errorf("unexpected stderr output:\n%s", stderr) + } + + if !strings.Contains(stdout, "Terraform has been successfully initialized!") { + t.Errorf("success message is missing from output:\n%s", stdout) + } + + if !strings.Contains(stdout, "- Installing registry.terraform.io/hashicorp/null v1.0.0+local") { + t.Errorf("provider download message is missing from output:\n%s", stdout) + t.Logf("(this can happen if you have a copy of the plugin in one of the global plugin search dirs)") + } + } func TestInitProviders_pluginCache(t *testing.T) { diff --git a/command/e2etest/testdata/vendored-provider/main.tf b/command/e2etest/testdata/vendored-provider/main.tf new file mode 100644 index 0000000000..3cb6215378 --- /dev/null +++ b/command/e2etest/testdata/vendored-provider/main.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + null = { + source = "hashicorp/null" + version = "1.0.0+local" + } + } +} diff --git a/command/e2etest/testdata/vendored-provider/terraform.d/plugins/registry.terraform.io/hashicorp/null/1.0.0+local/os_arch/terraform-provider-null_v1.0.0 b/command/e2etest/testdata/vendored-provider/terraform.d/plugins/registry.terraform.io/hashicorp/null/1.0.0+local/os_arch/terraform-provider-null_v1.0.0 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/command/init_test.go b/command/init_test.go index dc4ebc7859..baf26967c2 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -849,62 +849,6 @@ func TestInit_getProvider(t *testing.T) { }) } -// make sure we can locate providers in various paths -func TestInit_findVendoredProviders(t *testing.T) { - // Create a temporary working directory that is empty - td := tempDir(t) - - configDirName := "init-get-providers" - copy.CopyDir(testFixturePath(configDirName), filepath.Join(td, configDirName)) - defer os.RemoveAll(td) - defer testChdir(t, td)() - - // An empty provider source - providerSource, close := newMockProviderSource(t, nil) - defer close() - - ui := new(cli.MockUi) - m := Meta{ - testingOverrides: metaOverridesForProvider(testProvider()), - Ui: ui, - ProviderSource: providerSource, - } - - c := &InitCommand{ - Meta: m, - } - - // make our plugin paths - if err := os.MkdirAll(c.pluginDir(), 0755); err != nil { - t.Fatal(err) - } - if err := os.MkdirAll(DefaultPluginVendorDir, 0755); err != nil { - t.Fatal(err) - } - - // add some dummy providers - // the auto plugin directory - exactPath := filepath.Join(c.pluginDir(), "terraform-provider-exact_v1.2.3_x4") - if err := ioutil.WriteFile(exactPath, []byte("test bin"), 0755); err != nil { - t.Fatal(err) - } - // the vendor path - greaterThanPath := filepath.Join(DefaultPluginVendorDir, "terraform-provider-greater-than_v2.3.4_x4") - if err := ioutil.WriteFile(greaterThanPath, []byte("test bin"), 0755); err != nil { - t.Fatal(err) - } - // Check the current directory too - betweenPath := filepath.Join(".", "terraform-provider-between_v2.3.4_x4") - if err := ioutil.WriteFile(betweenPath, []byte("test bin"), 0755); err != nil { - t.Fatal(err) - } - - args := []string{configDirName} - if code := c.Run(args); code != 0 { - t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) - } -} - func TestInit_providerSource(t *testing.T) { // Create a temporary working directory that is empty td := tempDir(t)