mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
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:
parent
60718efc8e
commit
55222869bd
@ -85,18 +85,19 @@ func (n *EvalRefresh) Eval(ctx EvalContext) (interface{}, error) {
|
||||
return nil, diags.Err()
|
||||
}
|
||||
|
||||
state.Value = resp.NewState
|
||||
newState := state.DeepCopy()
|
||||
newState.Value = resp.NewState
|
||||
|
||||
// Call post-refresh hook
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if n.Output != nil {
|
||||
*n.Output = state
|
||||
*n.Output = newState
|
||||
}
|
||||
|
||||
return nil, diags.ErrWithWarnings()
|
||||
|
Loading…
Reference in New Issue
Block a user