DRY up the config.go
This commit is contained in:
parent
b51d18f1de
commit
f82b0552e0
72
config.go
72
config.go
|
@ -108,31 +108,10 @@ func (c *Config) ProviderFactories() map[string]terraform.ResourceProviderFactor
|
|||
}
|
||||
|
||||
func (c *Config) providerFactory(path string) terraform.ResourceProviderFactory {
|
||||
originalPath := path
|
||||
|
||||
return func() (terraform.ResourceProvider, error) {
|
||||
// First look for the provider on the PATH.
|
||||
path, err := exec.LookPath(path)
|
||||
if err != nil {
|
||||
// If that doesn't work, look for it in the same directory
|
||||
// as the executable that is running.
|
||||
exePath, err := osext.Executable()
|
||||
if err == nil {
|
||||
path = filepath.Join(
|
||||
filepath.Dir(exePath),
|
||||
filepath.Base(originalPath))
|
||||
}
|
||||
}
|
||||
|
||||
// If we still don't have a path set, then set it to the
|
||||
// original path and let any errors that happen bubble out.
|
||||
if path == "" {
|
||||
path = originalPath
|
||||
}
|
||||
|
||||
// Build the plugin client configuration and init the plugin
|
||||
var config plugin.ClientConfig
|
||||
config.Cmd = exec.Command(path)
|
||||
config.Cmd = pluginCmd(path)
|
||||
config.Managed = true
|
||||
client := plugin.NewClient(&config)
|
||||
|
||||
|
@ -168,31 +147,10 @@ func (c *Config) ProvisionerFactories() map[string]terraform.ResourceProvisioner
|
|||
}
|
||||
|
||||
func (c *Config) provisionerFactory(path string) terraform.ResourceProvisionerFactory {
|
||||
originalPath := path
|
||||
|
||||
return func() (terraform.ResourceProvisioner, error) {
|
||||
// First look for the provider on the PATH.
|
||||
path, err := exec.LookPath(path)
|
||||
if err != nil {
|
||||
// If that doesn't work, look for it in the same directory
|
||||
// as the executable that is running.
|
||||
exePath, err := osext.Executable()
|
||||
if err == nil {
|
||||
path = filepath.Join(
|
||||
filepath.Dir(exePath),
|
||||
filepath.Base(originalPath))
|
||||
}
|
||||
}
|
||||
|
||||
// If we still don't have a path set, then set it to the
|
||||
// original path and let any errors that happen bubble out.
|
||||
if path == "" {
|
||||
path = originalPath
|
||||
}
|
||||
|
||||
// Build the plugin client configuration and init the plugin
|
||||
var config plugin.ClientConfig
|
||||
config.Cmd = exec.Command(path)
|
||||
config.Cmd = pluginCmd(path)
|
||||
config.Managed = true
|
||||
client := plugin.NewClient(&config)
|
||||
|
||||
|
@ -214,3 +172,29 @@ func (c *Config) provisionerFactory(path string) terraform.ResourceProvisionerFa
|
|||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func pluginCmd(path string) *exec.Cmd {
|
||||
originalPath := path
|
||||
|
||||
// First look for the provider on the PATH.
|
||||
path, err := exec.LookPath(path)
|
||||
if err != nil {
|
||||
// If that doesn't work, look for it in the same directory
|
||||
// as the executable that is running.
|
||||
exePath, err := osext.Executable()
|
||||
if err == nil {
|
||||
path = filepath.Join(
|
||||
filepath.Dir(exePath),
|
||||
filepath.Base(originalPath))
|
||||
}
|
||||
}
|
||||
|
||||
// If we still don't have a path set, then set it to the
|
||||
// original path and let any errors that happen bubble out.
|
||||
if path == "" {
|
||||
path = originalPath
|
||||
}
|
||||
|
||||
// Build the command to execute the plugin
|
||||
return exec.Command(path)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue