github.com/hashicorp/terraform-plugin-sdk@v1.17.2/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-sdk/internal/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  		VersionedPlugins: VersionedPlugins,
    25  		Managed:          true,
    26  		Logger:           logger,
    27  		AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
    28  		AutoMTLS:         true,
    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  }