Skip to content

Commit

Permalink
Use hashicorp/go-plugin for plugin system
Browse files Browse the repository at this point in the history
This replaces this plugin system with the extracted hashicorp/go-plugin
library.

This doesn't introduce any new features such as binary flattening but
opens us up to that a lot more easily and removes a lot of code from TF
in favor of the upstream lib.

This will introduce a protocol change that will cause all existing
plugins to have to be recompiled to work properly. There is no actual
API changes so they just have to recompile, but it is technically
backwards incompatible.
  • Loading branch information
mitchellh authored and jen20 committed May 10, 2016
1 parent feb9cbe commit 8421443
Show file tree
Hide file tree
Showing 25 changed files with 966 additions and 2,149 deletions.
21 changes: 18 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"path/filepath"
"strings"

"github.com/hashicorp/go-plugin"
"github.com/hashicorp/hcl"
"github.com/hashicorp/terraform/plugin"
tfplugin "github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/terraform/terraform"
"github.com/kardianos/osext"
)
Expand Down Expand Up @@ -202,7 +203,9 @@ func (c *Config) providerFactory(path string) terraform.ResourceProviderFactory
// Build the plugin client configuration and init the plugin
var config plugin.ClientConfig
config.Cmd = pluginCmd(path)
config.HandshakeConfig = tfplugin.Handshake
config.Managed = true
config.Plugins = tfplugin.PluginMap
client := plugin.NewClient(&config)

return func() (terraform.ResourceProvider, error) {
Expand All @@ -213,7 +216,12 @@ func (c *Config) providerFactory(path string) terraform.ResourceProviderFactory
return nil, err
}

return rpcClient.ResourceProvider()
raw, err := rpcClient.Dispense(tfplugin.ProviderPluginName)
if err != nil {
return nil, err
}

return raw.(terraform.ResourceProvider), nil
}
}

Expand All @@ -232,8 +240,10 @@ func (c *Config) ProvisionerFactories() map[string]terraform.ResourceProvisioner
func (c *Config) provisionerFactory(path string) terraform.ResourceProvisionerFactory {
// Build the plugin client configuration and init the plugin
var config plugin.ClientConfig
config.HandshakeConfig = tfplugin.Handshake
config.Cmd = pluginCmd(path)
config.Managed = true
config.Plugins = tfplugin.PluginMap
client := plugin.NewClient(&config)

return func() (terraform.ResourceProvisioner, error) {
Expand All @@ -242,7 +252,12 @@ func (c *Config) provisionerFactory(path string) terraform.ResourceProvisionerFa
return nil, err
}

return rpcClient.ResourceProvisioner()
raw, err := rpcClient.Dispense(tfplugin.ProvisionerPluginName)
if err != nil {
return nil, err
}

return raw.(terraform.ResourceProvisioner), nil
}
}

Expand Down
339 changes: 0 additions & 339 deletions plugin/client.go

This file was deleted.

Loading

0 comments on commit 8421443

Please sign in to comment.