forked from hashicorp/terraform-plugin-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrpc_provider.go
41 lines (32 loc) · 1.26 KB
/
grpc_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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"
)
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 {
GRPCProvider func() proto.ProviderServer
}
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 {
proto.RegisterProviderServer(s, p.GRPCProvider())
return nil
}