]>
Commit | Line | Data |
---|---|---|
c680a8e1 RS |
1 | package plugin |
2 | ||
3 | import ( | |
15c0b25d | 4 | "os" |
c680a8e1 RS |
5 | "os/exec" |
6 | ||
15c0b25d | 7 | hclog "github.com/hashicorp/go-hclog" |
c680a8e1 RS |
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 { | |
15c0b25d AP |
15 | logger := hclog.New(&hclog.LoggerOptions{ |
16 | Name: "plugin", | |
17 | Level: hclog.Trace, | |
18 | Output: os.Stderr, | |
19 | }) | |
20 | ||
c680a8e1 | 21 | return &plugin.ClientConfig{ |
107c1cdb ND |
22 | Cmd: exec.Command(m.Path), |
23 | HandshakeConfig: Handshake, | |
24 | VersionedPlugins: VersionedPlugins, | |
25 | Managed: true, | |
26 | Logger: logger, | |
27 | AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC}, | |
28 | AutoMTLS: true, | |
c680a8e1 RS |
29 | } |
30 | } | |
31 | ||
32 | // Client returns a plugin client for the plugin described by the given metadata. | |
33 | func Client(m discovery.PluginMeta) *plugin.Client { | |
34 | return plugin.NewClient(ClientConfig(m)) | |
35 | } |