search the vendor directory for plugins
The default location for users to manually add plugins will be ./terraform.d/plugins/
This commit is contained in:
parent
06d4247a75
commit
f723270e3e
|
@ -15,6 +15,11 @@ var test bool = false
|
|||
// DefaultDataDir is the default directory for storing local data.
|
||||
const DefaultDataDir = ".terraform"
|
||||
|
||||
// DefaultPluginVendorDir is the location in the config directory to look for
|
||||
// user-added plugin binaries. Terraform only reads from this path if it
|
||||
// exists, it is never created by terraform.
|
||||
const DefaultPluginVendorDir = "terraform.d/plugins"
|
||||
|
||||
// DefaultStateFilename is the default filename used for the state file.
|
||||
const DefaultStateFilename = "terraform.tfstate"
|
||||
|
||||
|
|
|
@ -494,6 +494,63 @@ 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)()
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
m := Meta{
|
||||
testingOverrides: metaOverridesForProvider(testProvider()),
|
||||
Ui: ui,
|
||||
}
|
||||
|
||||
c := &InitCommand{
|
||||
Meta: m,
|
||||
providerInstaller: &mockProviderInstaller{},
|
||||
}
|
||||
|
||||
// make our plugin paths
|
||||
if err := os.MkdirAll(c.pluginDir(), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vendorMachineDir := filepath.Join(
|
||||
DefaultPluginVendorDir,
|
||||
fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH),
|
||||
)
|
||||
if err := os.MkdirAll(vendorMachineDir, 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(vendorMachineDir, "terraform-provider-greater_than_v2.3.4_x4")
|
||||
if err := ioutil.WriteFile(greaterThanPath, []byte("test bin"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// TODO: change this to the -plugin-dir path
|
||||
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_getUpgradePlugins(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := tempDir(t)
|
||||
|
|
|
@ -97,10 +97,14 @@ func (m *Meta) pluginDirs(includeAutoInstalled bool) []string {
|
|||
dirs = append(dirs, filepath.Dir(exePath))
|
||||
}
|
||||
|
||||
// add the user vendor directory
|
||||
dirs = append(dirs, DefaultPluginVendorDir)
|
||||
|
||||
if includeAutoInstalled {
|
||||
dirs = append(dirs, m.pluginDir())
|
||||
}
|
||||
dirs = append(dirs, m.GlobalPluginDirs...)
|
||||
|
||||
return dirs
|
||||
}
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@ func findPluginPaths(kind string, machineName string, dirs []string) []string {
|
|||
continue
|
||||
}
|
||||
|
||||
// FIXME: we pass in GOOS_GOARCH paths directly, so these may not be "legacy"
|
||||
if strings.HasPrefix(fullName, prefix) {
|
||||
// Legacy style with files directly in the base directory
|
||||
absPath, err := filepath.Abs(filepath.Join(baseDir, fullName))
|
||||
|
|
Loading…
Reference in New Issue