Skip to content

Commit

Permalink
Merge pull request #348 from hashicorp/fix-serve
Browse files Browse the repository at this point in the history
Fix plugin.Serve
  • Loading branch information
appilon committed Mar 10, 2020
2 parents a482dd3 + 0a3c887 commit 63c7262
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions plugin/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ package plugin

import (
"context"
"errors"
"net/rpc"

plugin "github.com/hashicorp/go-plugin"
"google.golang.org/grpc"

proto "github.com/hashicorp/terraform-plugin-sdk/v2/internal/tfplugin5"
)

// GRPCProviderPlugin implements plugin.GRPCPlugin for the go-plugin package.
var (
_ plugin.GRPCPlugin = (*gRPCProviderPlugin)(nil)
_ plugin.Plugin = (*gRPCProviderPlugin)(nil)
)

// gRPCProviderPlugin implements plugin.GRPCPlugin and plugin.Plugin for the go-plugin package.
// the only real implementation is GRPCSServer, the other methods are only satisfied
// for compatibility with go-plugin
type gRPCProviderPlugin struct {
plugin.Plugin
GRPCProvider func() proto.ProviderServer
}

// this exists only to satisfy the go-plugin.GRPCPlugin interface
// that interface should likely be split
func (p *gRPCProviderPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return nil, nil
func (p *gRPCProviderPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
return nil, errors.New("terraform-plugin-sdk only implements grpc servers")
}

func (p *gRPCProviderPlugin) Client(*plugin.MuxBroker, *rpc.Client) (interface{}, error) {
return nil, errors.New("terraform-plugin-sdk only implements grpc servers")
}

func (p *gRPCProviderPlugin) GRPCClient(context.Context, *plugin.GRPCBroker, *grpc.ClientConn) (interface{}, error) {
return nil, errors.New("terraform-plugin-sdk only implements grpc servers")
}

func (p *gRPCProviderPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
Expand Down
2 changes: 1 addition & 1 deletion plugin/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Serve(opts *ServeOpts) {
HandshakeConfig: Handshake,
VersionedPlugins: map[int]plugin.PluginSet{
5: {
ProviderPluginName: gRPCProviderPlugin{
ProviderPluginName: &gRPCProviderPlugin{
GRPCProvider: func() proto.ProviderServer {
return provider
},
Expand Down

0 comments on commit 63c7262

Please sign in to comment.