update plugin client with PrepareProviderConfig
This commit is contained in:
parent
b173037eb3
commit
3bdd3b2a6e
|
@ -147,26 +147,38 @@ func (p *GRPCProvider) GetSchema() (resp providers.GetSchemaResponse) {
|
|||
return resp
|
||||
}
|
||||
|
||||
func (p *GRPCProvider) ValidateProviderConfig(r providers.ValidateProviderConfigRequest) (resp providers.ValidateProviderConfigResponse) {
|
||||
log.Printf("[TRACE] GRPCProvider: ValidateProviderConfig")
|
||||
func (p *GRPCProvider) PrepareProviderConfig(r providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) {
|
||||
log.Printf("[TRACE] GRPCProvider: PrepareProviderConfig")
|
||||
|
||||
schema := p.getSchema()
|
||||
mp, err := msgpack.Marshal(r.Config, schema.Provider.Block.ImpliedType())
|
||||
ty := schema.Provider.Block.ImpliedType()
|
||||
|
||||
mp, err := msgpack.Marshal(r.Config, ty)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
|
||||
protoReq := &proto.ValidateProviderConfig_Request{
|
||||
protoReq := &proto.PrepareProviderConfig_Request{
|
||||
Config: &proto.DynamicValue{Msgpack: mp},
|
||||
}
|
||||
|
||||
protoResp, err := p.client.ValidateProviderConfig(p.ctx, protoReq)
|
||||
protoResp, err := p.client.PrepareProviderConfig(p.ctx, protoReq)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
|
||||
config := cty.NullVal(ty)
|
||||
if protoResp.PreparedConfig != nil {
|
||||
config, err = msgpack.Unmarshal(protoResp.PreparedConfig.Msgpack, ty)
|
||||
if err != nil {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(err)
|
||||
return resp
|
||||
}
|
||||
}
|
||||
resp.PreparedConfig = config
|
||||
|
||||
resp.Diagnostics = resp.Diagnostics.Append(convert.ProtoToDiagnostics(protoResp.Diagnostics))
|
||||
return resp
|
||||
}
|
||||
|
|
|
@ -91,19 +91,19 @@ func TestGRPCProvider_GetSchema(t *testing.T) {
|
|||
checkDiags(t, resp.Diagnostics)
|
||||
}
|
||||
|
||||
func TestGRPCProvider_ValidateProviderConfig(t *testing.T) {
|
||||
func TestGRPCProvider_PrepareProviderConfig(t *testing.T) {
|
||||
client := mockProviderClient(t)
|
||||
p := &GRPCProvider{
|
||||
client: client,
|
||||
}
|
||||
|
||||
client.EXPECT().ValidateProviderConfig(
|
||||
client.EXPECT().PrepareProviderConfig(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(&proto.ValidateProviderConfig_Response{}, nil)
|
||||
).Return(&proto.PrepareProviderConfig_Response{}, nil)
|
||||
|
||||
cfg := hcl2shim.HCL2ValueFromConfigValue(map[string]interface{}{"attr": "value"})
|
||||
resp := p.ValidateProviderConfig(providers.ValidateProviderConfigRequest{Config: cfg})
|
||||
resp := p.PrepareProviderConfig(providers.PrepareProviderConfigRequest{Config: cfg})
|
||||
checkDiags(t, resp.Diagnostics)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue