github.com/posener/terraform@v0.11.0-beta1.0.20171103235147-645df36af025/plugin/client.go (about) 1 package plugin 2 3 import ( 4 "os" 5 "os/exec" 6 7 hclog "github.com/hashicorp/go-hclog" 8 plugin "github.com/hashicorp/go-plugin" 9 "github.com/hashicorp/terraform/plugin/discovery" 10 ) 11 12 // ClientConfig returns a configuration object that can be used to instantiate 13 // a client for the plugin described by the given metadata. 14 func ClientConfig(m discovery.PluginMeta) *plugin.ClientConfig { 15 logger := hclog.New(&hclog.LoggerOptions{ 16 Name: "plugin", 17 Level: hclog.Trace, 18 Output: os.Stderr, 19 }) 20 21 return &plugin.ClientConfig{ 22 Cmd: exec.Command(m.Path), 23 HandshakeConfig: Handshake, 24 Managed: true, 25 Plugins: PluginMap, 26 Logger: logger, 27 } 28 } 29 30 // Client returns a plugin client for the plugin described by the given metadata. 31 func Client(m discovery.PluginMeta) *plugin.Client { 32 return plugin.NewClient(ClientConfig(m)) 33 }