core: EvalRefresh should not mutate the state object it is given

We now treat states.ResourceInstanceObject values as immutable once
constructed, preferring to replace them completely rather than update them
in-place to avoid weird race conditions.

Therefore EvalRefresh must copy the state it is given before mutating the
Value field of it to reflect the updated value from the provider.
This commit is contained in:
Martin Atkins 2018-09-12 11:15:31 -07:00
parent 60718efc8e
commit 55222869bd

View File

@ -85,18 +85,19 @@ func (n *EvalRefresh) Eval(ctx EvalContext) (interface{}, error) {
return nil, diags.Err() return nil, diags.Err()
} }
state.Value = resp.NewState newState := state.DeepCopy()
newState.Value = resp.NewState
// Call post-refresh hook // Call post-refresh hook
err = ctx.Hook(func(h Hook) (HookAction, error) { err = ctx.Hook(func(h Hook) (HookAction, error) {
return h.PostRefresh(absAddr, states.CurrentGen, priorVal, state.Value) return h.PostRefresh(absAddr, states.CurrentGen, priorVal, newState.Value)
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
if n.Output != nil { if n.Output != nil {
*n.Output = state *n.Output = newState
} }
return nil, diags.ErrWithWarnings() return nil, diags.ErrWithWarnings()