mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 16:31:10 -06:00
714df97a02
The go-plugin package now uses hclog. The default Logger has a level set to Info, but all plugin output is relayed via Debug. Create a new named logger for plugins with the level set to Trace so that all output comes through.
34 lines
861 B
Go
34 lines
861 B
Go
package plugin
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
|
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 {
|
|
logger := hclog.New(&hclog.LoggerOptions{
|
|
Name: "plugin",
|
|
Level: hclog.Trace,
|
|
Output: os.Stderr,
|
|
})
|
|
|
|
return &plugin.ClientConfig{
|
|
Cmd: exec.Command(m.Path),
|
|
HandshakeConfig: Handshake,
|
|
Managed: true,
|
|
Plugins: PluginMap,
|
|
Logger: logger,
|
|
}
|
|
}
|
|
|
|
// 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))
|
|
}
|