add grpc shims to helper/plugin

Add shim functions to automatically wrap plugins in the new GRPC
implementations.
This commit is contained in:
James Bardin 2018-08-14 16:39:30 -04:00 committed by Martin Atkins
parent 5e7956f440
commit 7188d5cbfe
2 changed files with 27 additions and 0 deletions

View File

@ -16,6 +16,20 @@ import (
"github.com/zclconf/go-cty/cty/msgpack"
)
// NewGRPCProviderServerShim wraps a terraform.ResourceProvider in a
// proto.ProviderServer implementation. If the provided provider is not a
// *schema.Provider, this will return nil,
func NewGRPCProviderServerShim(p terraform.ResourceProvider) *GRPCProviderServer {
sp, ok := p.(*schema.Provider)
if !ok {
return nil
}
return &GRPCProviderServer{
provider: sp,
}
}
// GRPCProviderServer handles the server, or plugin side of the rpc connection.
type GRPCProviderServer struct {
provider *schema.Provider

View File

@ -12,6 +12,19 @@ import (
context "golang.org/x/net/context"
)
// NewGRPCProvisionerServerShim wraps a terraform.ResourceProvisioner in a
// proto.ProvisionerServer implementation. If the provided provisioner is not a
// *schema.Provisioner, this will return nil,
func NewGRPCProvisionerServerShim(p terraform.ResourceProvisioner) *GRPCProvisionerServer {
sp, ok := p.(*schema.Provisioner)
if !ok {
return nil
}
return &GRPCProvisionerServer{
provisioner: sp,
}
}
type GRPCProvisionerServer struct {
provisioner *schema.Provisioner
}