mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-03-10 10:01:16 -04:00
Previously we did plugin discovery in the main package, but as we move towards versioned plugins we need more information available in order to resolve plugins, so we move this responsibility into the command package itself. For the moment this is just preserving the existing behavior as long as there are only internal and unversioned plugins present. This is the final state for provisioners in 0.10, since we don't want to support versioned provisioners yet. For providers this is just a checkpoint along the way, since further work is required to apply version constraints from configuration and support additional plugin search directories. The automatic plugin discovery behavior is not desirable for tests because we want to mock the plugins there, so we add a new backdoor for the tests to use to skip the plugin discovery and just provide their own mock implementations. Most of this diff is thus noisy rework of the tests to use this new mechanism.
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"path/filepath"
|
|
|
|
"github.com/kardianos/osext"
|
|
)
|
|
|
|
// globalPluginDirs returns directories that should be searched for
|
|
// globally-installed plugins (not specific to the current configuration).
|
|
//
|
|
// Earlier entries in this slice get priority over later when multiple copies
|
|
// of the same plugin version are found, but newer versions always override
|
|
// older versions where both satisfy the provider version constraints.
|
|
func globalPluginDirs() []string {
|
|
var ret []string
|
|
|
|
// Look in the same directory as the Terraform executable.
|
|
// If found, this replaces what we found in the config path.
|
|
exePath, err := osext.Executable()
|
|
if err != nil {
|
|
log.Printf("[ERROR] Error discovering exe directory: %s", err)
|
|
} else {
|
|
ret = append(ret, filepath.Dir(exePath))
|
|
}
|
|
|
|
// Look in ~/.terraform.d/plugins/ , or its equivalent on non-UNIX
|
|
dir, err := ConfigDir()
|
|
if err != nil {
|
|
log.Printf("[ERROR] Error finding global config directory: %s", err)
|
|
} else {
|
|
ret = append(ret, filepath.Join(dir, "plugins"))
|
|
}
|
|
|
|
return ret
|
|
}
|