2020-11-20 00:34:58 +01:00
|
|
|
package grpcwrap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/internal/tfplugin5"
|
|
|
|
"github.com/hashicorp/terraform/plugin/convert"
|
|
|
|
"github.com/hashicorp/terraform/providers"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
ctyjson "github.com/zclconf/go-cty/cty/json"
|
|
|
|
"github.com/zclconf/go-cty/cty/msgpack"
|
|
|
|
)
|
|
|
|
|
|
|
|
// New wraps a providers.Interface to implement a grpc ProviderServer.
|
|
|
|
// This is useful for creating a test binary out of an internal provider
|
|
|
|
// implementation.
|
2020-11-26 00:02:21 +01:00
|
|
|
func Provider(p providers.Interface) tfplugin5.ProviderServer {
|
|
|
|
return &provider{
|
2020-11-20 00:34:58 +01:00
|
|
|
provider: p,
|
|
|
|
schema: p.GetSchema(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
type provider struct {
|
2020-11-20 00:34:58 +01:00
|
|
|
provider providers.Interface
|
|
|
|
schema providers.GetSchemaResponse
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) GetSchema(_ context.Context, req *tfplugin5.GetProviderSchema_Request) (*tfplugin5.GetProviderSchema_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.GetProviderSchema_Response{
|
|
|
|
ResourceSchemas: make(map[string]*tfplugin5.Schema),
|
|
|
|
DataSourceSchemas: make(map[string]*tfplugin5.Schema),
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.Provider = &tfplugin5.Schema{
|
|
|
|
Block: &tfplugin5.Schema_Block{},
|
|
|
|
}
|
2020-11-26 00:02:21 +01:00
|
|
|
if p.schema.Provider.Block != nil {
|
|
|
|
resp.Provider.Block = convert.ConfigSchemaToProto(p.schema.Provider.Block)
|
2020-11-20 00:34:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resp.ProviderMeta = &tfplugin5.Schema{
|
|
|
|
Block: &tfplugin5.Schema_Block{},
|
|
|
|
}
|
2020-11-26 00:02:21 +01:00
|
|
|
if p.schema.ProviderMeta.Block != nil {
|
|
|
|
resp.ProviderMeta.Block = convert.ConfigSchemaToProto(p.schema.ProviderMeta.Block)
|
2020-11-20 00:34:58 +01:00
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
for typ, res := range p.schema.ResourceTypes {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp.ResourceSchemas[typ] = &tfplugin5.Schema{
|
|
|
|
Version: res.Version,
|
|
|
|
Block: convert.ConfigSchemaToProto(res.Block),
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 00:02:21 +01:00
|
|
|
for typ, dat := range p.schema.DataSources {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp.DataSourceSchemas[typ] = &tfplugin5.Schema{
|
|
|
|
Version: dat.Version,
|
|
|
|
Block: convert.ConfigSchemaToProto(dat.Block),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// include any diagnostics from the original GetSchema call
|
2020-11-26 00:02:21 +01:00
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, p.schema.Diagnostics)
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) PrepareProviderConfig(_ context.Context, req *tfplugin5.PrepareProviderConfig_Request) (*tfplugin5.PrepareProviderConfig_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.PrepareProviderConfig_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.Provider.Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
configVal, err := decodeDynamicValue(req.Config, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
prepareResp := p.provider.PrepareProviderConfig(providers.PrepareProviderConfigRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
Config: configVal,
|
|
|
|
})
|
|
|
|
|
|
|
|
// the PreparedConfig value is no longer used
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, prepareResp.Diagnostics)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) ValidateResourceTypeConfig(_ context.Context, req *tfplugin5.ValidateResourceTypeConfig_Request) (*tfplugin5.ValidateResourceTypeConfig_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.ValidateResourceTypeConfig_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.ResourceTypes[req.TypeName].Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
configVal, err := decodeDynamicValue(req.Config, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
validateResp := p.provider.ValidateResourceTypeConfig(providers.ValidateResourceTypeConfigRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TypeName: req.TypeName,
|
|
|
|
Config: configVal,
|
|
|
|
})
|
|
|
|
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, validateResp.Diagnostics)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) ValidateDataSourceConfig(_ context.Context, req *tfplugin5.ValidateDataSourceConfig_Request) (*tfplugin5.ValidateDataSourceConfig_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.ValidateDataSourceConfig_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.DataSources[req.TypeName].Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
configVal, err := decodeDynamicValue(req.Config, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
validateResp := p.provider.ValidateDataSourceConfig(providers.ValidateDataSourceConfigRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TypeName: req.TypeName,
|
|
|
|
Config: configVal,
|
|
|
|
})
|
|
|
|
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, validateResp.Diagnostics)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) UpgradeResourceState(_ context.Context, req *tfplugin5.UpgradeResourceState_Request) (*tfplugin5.UpgradeResourceState_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.UpgradeResourceState_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.ResourceTypes[req.TypeName].Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
upgradeResp := p.provider.UpgradeResourceState(providers.UpgradeResourceStateRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TypeName: req.TypeName,
|
|
|
|
Version: req.Version,
|
|
|
|
RawStateJSON: req.RawState.Json,
|
|
|
|
})
|
|
|
|
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, upgradeResp.Diagnostics)
|
|
|
|
if upgradeResp.Diagnostics.HasErrors() {
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
dv, err := encodeDynamicValue(upgradeResp.UpgradedState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.UpgradedState = dv
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) Configure(_ context.Context, req *tfplugin5.Configure_Request) (*tfplugin5.Configure_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.Configure_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.Provider.Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
configVal, err := decodeDynamicValue(req.Config, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
configureResp := p.provider.Configure(providers.ConfigureRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TerraformVersion: req.TerraformVersion,
|
|
|
|
Config: configVal,
|
|
|
|
})
|
|
|
|
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, configureResp.Diagnostics)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) ReadResource(_ context.Context, req *tfplugin5.ReadResource_Request) (*tfplugin5.ReadResource_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.ReadResource_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.ResourceTypes[req.TypeName].Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
stateVal, err := decodeDynamicValue(req.CurrentState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
metaTy := p.schema.ProviderMeta.Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
metaVal, err := decodeDynamicValue(req.ProviderMeta, metaTy)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
readResp := p.provider.ReadResource(providers.ReadResourceRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TypeName: req.TypeName,
|
|
|
|
PriorState: stateVal,
|
|
|
|
Private: req.Private,
|
|
|
|
ProviderMeta: metaVal,
|
|
|
|
})
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, readResp.Diagnostics)
|
|
|
|
if readResp.Diagnostics.HasErrors() {
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
resp.Private = readResp.Private
|
|
|
|
|
|
|
|
dv, err := encodeDynamicValue(readResp.NewState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
resp.NewState = dv
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) PlanResourceChange(_ context.Context, req *tfplugin5.PlanResourceChange_Request) (*tfplugin5.PlanResourceChange_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.PlanResourceChange_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.ResourceTypes[req.TypeName].Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
priorStateVal, err := decodeDynamicValue(req.PriorState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
proposedStateVal, err := decodeDynamicValue(req.ProposedNewState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
configVal, err := decodeDynamicValue(req.Config, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
metaTy := p.schema.ProviderMeta.Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
metaVal, err := decodeDynamicValue(req.ProviderMeta, metaTy)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
planResp := p.provider.PlanResourceChange(providers.PlanResourceChangeRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TypeName: req.TypeName,
|
|
|
|
PriorState: priorStateVal,
|
|
|
|
ProposedNewState: proposedStateVal,
|
|
|
|
Config: configVal,
|
|
|
|
PriorPrivate: req.PriorPrivate,
|
|
|
|
ProviderMeta: metaVal,
|
|
|
|
})
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, planResp.Diagnostics)
|
|
|
|
if planResp.Diagnostics.HasErrors() {
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.PlannedPrivate = planResp.PlannedPrivate
|
|
|
|
|
|
|
|
resp.PlannedState, err = encodeDynamicValue(planResp.PlannedState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, path := range planResp.RequiresReplace {
|
|
|
|
resp.RequiresReplace = append(resp.RequiresReplace, convert.PathToAttributePath(path))
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) ApplyResourceChange(_ context.Context, req *tfplugin5.ApplyResourceChange_Request) (*tfplugin5.ApplyResourceChange_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.ApplyResourceChange_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.ResourceTypes[req.TypeName].Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
priorStateVal, err := decodeDynamicValue(req.PriorState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
plannedStateVal, err := decodeDynamicValue(req.PlannedState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
configVal, err := decodeDynamicValue(req.Config, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
metaTy := p.schema.ProviderMeta.Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
metaVal, err := decodeDynamicValue(req.ProviderMeta, metaTy)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
applyResp := p.provider.ApplyResourceChange(providers.ApplyResourceChangeRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TypeName: req.TypeName,
|
|
|
|
PriorState: priorStateVal,
|
|
|
|
PlannedState: plannedStateVal,
|
|
|
|
Config: configVal,
|
|
|
|
PlannedPrivate: req.PlannedPrivate,
|
|
|
|
ProviderMeta: metaVal,
|
|
|
|
})
|
|
|
|
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, applyResp.Diagnostics)
|
|
|
|
if applyResp.Diagnostics.HasErrors() {
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
resp.Private = applyResp.Private
|
|
|
|
|
|
|
|
resp.NewState, err = encodeDynamicValue(applyResp.NewState, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) ImportResourceState(_ context.Context, req *tfplugin5.ImportResourceState_Request) (*tfplugin5.ImportResourceState_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.ImportResourceState_Response{}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
importResp := p.provider.ImportResourceState(providers.ImportResourceStateRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TypeName: req.TypeName,
|
|
|
|
ID: req.Id,
|
|
|
|
})
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, importResp.Diagnostics)
|
|
|
|
|
|
|
|
for _, res := range importResp.ImportedResources {
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.ResourceTypes[res.TypeName].Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
state, err := encodeDynamicValue(res.State, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.ImportedResources = append(resp.ImportedResources, &tfplugin5.ImportResourceState_ImportedResource{
|
|
|
|
TypeName: res.TypeName,
|
|
|
|
State: state,
|
|
|
|
Private: res.Private,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) ReadDataSource(_ context.Context, req *tfplugin5.ReadDataSource_Request) (*tfplugin5.ReadDataSource_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.ReadDataSource_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
ty := p.schema.DataSources[req.TypeName].Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
|
|
|
|
configVal, err := decodeDynamicValue(req.Config, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
metaTy := p.schema.ProviderMeta.Block.ImpliedType()
|
2020-11-20 00:34:58 +01:00
|
|
|
metaVal, err := decodeDynamicValue(req.ProviderMeta, metaTy)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
readResp := p.provider.ReadDataSource(providers.ReadDataSourceRequest{
|
2020-11-20 00:34:58 +01:00
|
|
|
TypeName: req.TypeName,
|
|
|
|
Config: configVal,
|
|
|
|
ProviderMeta: metaVal,
|
|
|
|
})
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, readResp.Diagnostics)
|
|
|
|
if readResp.Diagnostics.HasErrors() {
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.State, err = encodeDynamicValue(readResp.State, ty)
|
|
|
|
if err != nil {
|
|
|
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-11-26 00:02:21 +01:00
|
|
|
func (p *provider) Stop(context.Context, *tfplugin5.Stop_Request) (*tfplugin5.Stop_Response, error) {
|
2020-11-20 00:34:58 +01:00
|
|
|
resp := &tfplugin5.Stop_Response{}
|
2020-11-26 00:02:21 +01:00
|
|
|
err := p.provider.Stop()
|
2020-11-20 00:34:58 +01:00
|
|
|
if err != nil {
|
|
|
|
resp.Error = err.Error()
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// decode a DynamicValue from either the JSON or MsgPack encoding.
|
|
|
|
func decodeDynamicValue(v *tfplugin5.DynamicValue, ty cty.Type) (cty.Value, error) {
|
|
|
|
// always return a valid value
|
|
|
|
var err error
|
|
|
|
res := cty.NullVal(ty)
|
|
|
|
if v == nil {
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case len(v.Msgpack) > 0:
|
|
|
|
res, err = msgpack.Unmarshal(v.Msgpack, ty)
|
|
|
|
case len(v.Json) > 0:
|
|
|
|
res, err = ctyjson.Unmarshal(v.Json, ty)
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// encode a cty.Value into a DynamicValue msgpack payload.
|
|
|
|
func encodeDynamicValue(v cty.Value, ty cty.Type) (*tfplugin5.DynamicValue, error) {
|
|
|
|
mp, err := msgpack.Marshal(v, ty)
|
|
|
|
return &tfplugin5.DynamicValue{
|
|
|
|
Msgpack: mp,
|
|
|
|
}, err
|
|
|
|
}
|