send and receive Private through ReadResource

Send Private data blob through ReadResource as well. This will allow for
extra flexibility for future providers that may want to pass data out of
band through to their resource Read functions.
This commit is contained in:
James Bardin 2019-06-03 18:08:26 -04:00
parent e2b2f1bbbc
commit dcab82e897
4 changed files with 17 additions and 0 deletions

View File

@ -535,6 +535,11 @@ func (s *GRPCProviderServer) ReadResource(_ context.Context, req *proto.ReadReso
Msgpack: newStateMP,
}
// helper/schema did previously handle private data during refresh, but
// core is now going to expect this to be maintained in order to
// persist it in the state.
resp.Private = req.Private
return resp, nil
}

View File

@ -330,6 +330,7 @@ func (p *GRPCProvider) ReadResource(r providers.ReadResourceRequest) (resp provi
protoReq := &proto.ReadResource_Request{
TypeName: r.TypeName,
CurrentState: &proto.DynamicValue{Msgpack: mp},
Private: r.Private,
}
protoResp, err := p.client.ReadResource(p.ctx, protoReq)
@ -348,6 +349,7 @@ func (p *GRPCProvider) ReadResource(r providers.ReadResourceRequest) (resp provi
}
}
resp.NewState = state
resp.Private = protoResp.Private
return resp
}

View File

@ -176,6 +176,10 @@ type ReadResourceRequest struct {
// PriorState contains the previously saved state value for this resource.
PriorState cty.Value
// Private is an opaque blob that will be stored in state along with the
// resource. It is intended only for interpretation by the provider itself.
Private []byte
}
type ReadResourceResponse struct {
@ -184,6 +188,10 @@ type ReadResourceResponse struct {
// Diagnostics contains any warnings or errors from the method call.
Diagnostics tfdiags.Diagnostics
// Private is an opaque blob that will be stored in state along with the
// resource. It is intended only for interpretation by the provider itself.
Private []byte
}
type PlanResourceChangeRequest struct {

View File

@ -55,6 +55,7 @@ func (n *EvalRefresh) Eval(ctx EvalContext) (interface{}, error) {
req := providers.ReadResourceRequest{
TypeName: n.Addr.Resource.Type,
PriorState: priorVal,
Private: state.Private,
}
provider := *n.Provider
@ -87,6 +88,7 @@ func (n *EvalRefresh) Eval(ctx EvalContext) (interface{}, error) {
newState := state.DeepCopy()
newState.Value = resp.NewState
newState.Private = resp.Private
// Call post-refresh hook
err = ctx.Hook(func(h Hook) (HookAction, error) {