2017-04-15 02:24:08 +02:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2017-08-15 20:15:00 +02:00
|
|
|
"os"
|
2017-04-15 02:24:08 +02:00
|
|
|
"os/exec"
|
|
|
|
|
2017-08-15 20:15:00 +02:00
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
2017-04-15 02:24:08 +02:00
|
|
|
plugin "github.com/hashicorp/go-plugin"
|
|
|
|
"github.com/hashicorp/terraform/plugin/discovery"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ClientConfig returns a configuration object that can be used to instantiate
|
|
|
|
// a client for the plugin described by the given metadata.
|
|
|
|
func ClientConfig(m discovery.PluginMeta) *plugin.ClientConfig {
|
2017-08-15 20:15:00 +02:00
|
|
|
logger := hclog.New(&hclog.LoggerOptions{
|
|
|
|
Name: "plugin",
|
|
|
|
Level: hclog.Trace,
|
|
|
|
Output: os.Stderr,
|
|
|
|
})
|
|
|
|
|
2017-04-15 02:24:08 +02:00
|
|
|
return &plugin.ClientConfig{
|
2018-08-25 01:13:50 +02:00
|
|
|
Cmd: exec.Command(m.Path),
|
|
|
|
HandshakeConfig: Handshake,
|
|
|
|
VersionedPlugins: VersionedPlugins,
|
|
|
|
Managed: true,
|
|
|
|
Logger: logger,
|
|
|
|
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
|
2017-04-15 02:24:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client returns a plugin client for the plugin described by the given metadata.
|
|
|
|
func Client(m discovery.PluginMeta) *plugin.Client {
|
|
|
|
return plugin.NewClient(ClientConfig(m))
|
|
|
|
}
|