update Refresh

Use the new ReadResource provider method
This commit is contained in:
James Bardin 2018-08-16 13:05:05 -04:00 committed by Martin Atkins
parent 16df9c37cf
commit ad7eee7ba4
1 changed files with 10 additions and 8 deletions

View File

@ -39,17 +39,19 @@ func (n *EvalRefresh) Eval(ctx EvalContext) (interface{}, error) {
// Refresh!
priorVal := state.Value
// TODO: Shim our new state type into the old one
//provider := *n.Provider
//state, err = provider.Refresh(legacyInfo, state)
return nil, fmt.Errorf("EvalRefresh is not yet updated for new state type")
if err != nil {
return nil, fmt.Errorf("%s: %s", n.Addr.Absolute(ctx.Path()), err.Error())
req := providers.ReadResourceRequest{
TypeName: n.Addr.Resource.Type,
PriorState: priorVal,
}
if state == nil {
log.Printf("[TRACE] EvalRefresh: after refresh, %s has nil state", n.Addr)
provider := *n.Provider
resp := provider.ReadResource(req)
if resp.Diagnostics.HasErrors() {
return nil, fmt.Errorf("%s: %s", n.Addr.Absolute(ctx.Path()), resp.Diagnostics.Err())
}
state.Value = resp.NewState
// Call post-refresh hook
err = ctx.Hook(func(h Hook) (HookAction, error) {
return h.PostRefresh(absAddr, states.CurrentGen, priorVal, state.Value)