diff --git a/command/plugins.go b/command/plugins.go index 113378db00..fa4e48ab4a 100644 --- a/command/plugins.go +++ b/command/plugins.go @@ -50,7 +50,7 @@ func (m *Meta) providerFactories() map[string]terraform.ResourceProviderFactory // by name, we're guaranteed that the metas in our set all have // valid versions and that there's at least one meta. newest := metas.Newest() - client := newest.Client() + client := tfplugin.Client(newest) factories[name] = providerFactory(client) } @@ -99,7 +99,7 @@ func (m *Meta) provisionerFactories() map[string]terraform.ResourceProvisionerFa // by name, we're guaranteed that the metas in our set all have // valid versions and that there's at least one meta. newest := metas.Newest() - client := newest.Client() + client := tfplugin.Client(newest) factories[name] = provisionerFactory(client) } diff --git a/plugin/client.go b/plugin/client.go new file mode 100644 index 0000000000..3a5cb7af05 --- /dev/null +++ b/plugin/client.go @@ -0,0 +1,24 @@ +package plugin + +import ( + "os/exec" + + 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 { + return &plugin.ClientConfig{ + Cmd: exec.Command(m.Path), + HandshakeConfig: Handshake, + Managed: true, + Plugins: PluginMap, + } +} + +// 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)) +} diff --git a/plugin/discovery/meta.go b/plugin/discovery/meta.go index 0c3a1ff4af..d93296cfc6 100644 --- a/plugin/discovery/meta.go +++ b/plugin/discovery/meta.go @@ -4,11 +4,8 @@ import ( "crypto/sha256" "io" "os" - "os/exec" "github.com/blang/semver" - plugin "github.com/hashicorp/go-plugin" - tfplugin "github.com/hashicorp/terraform/plugin" ) // PluginMeta is metadata about a plugin, useful for launching the plugin @@ -51,19 +48,3 @@ func (m PluginMeta) SHA256() ([]byte, error) { return h.Sum(nil), nil } - -// ClientConfig returns a configuration object that can be used to instantiate -// a client for the referenced plugin. -func (m PluginMeta) ClientConfig() *plugin.ClientConfig { - return &plugin.ClientConfig{ - Cmd: exec.Command(m.Path), - HandshakeConfig: tfplugin.Handshake, - Managed: true, - Plugins: tfplugin.PluginMap, - } -} - -// Client returns a plugin client for the referenced plugin. -func (m PluginMeta) Client() *plugin.Client { - return plugin.NewClient(m.ClientConfig()) -}