Skip to content

Commit

Permalink
send and receive Private through ReadResource
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbardin committed Jun 3, 2019
1 parent e2b2f1b commit dcab82e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helper/plugin/grpc_provider.go
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions plugin/grpc_provider.go
Expand Up @@ -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)
Expand All @@ -348,6 +349,7 @@ func (p *GRPCProvider) ReadResource(r providers.ReadResourceRequest) (resp provi
}
}
resp.NewState = state
resp.Private = protoResp.Private

return resp
}
Expand Down
8 changes: 8 additions & 0 deletions providers/provider.go
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions terraform/eval_refresh.go
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dcab82e

Please sign in to comment.