Add RefreshState to the eval context

Since plan uses the state as a scratch space for evaluation, we need an
entirely separate state to store the refreshed resources values during
planning. Add a RefreshState method to the EvalContext to retrieve a
state used only for refreshing resources.
This commit is contained in:
James Bardin 2020-09-04 15:53:15 -04:00
parent be757bd416
commit d6a586709c
3 changed files with 18 additions and 0 deletions

View File

@ -152,6 +152,11 @@ type EvalContext interface {
// the global state.
State() *states.SyncState
// RefreshState returns a wrapper object that provides safe concurrent
// access to the state used to store the most recently refreshed resource
// values.
RefreshState() *states.SyncState
// InstanceExpander returns a helper object for tracking the expansion of
// graph nodes during the plan phase in response to "count" and "for_each"
// arguments.

View File

@ -71,6 +71,7 @@ type BuiltinEvalContext struct {
ProvisionerLock *sync.Mutex
ChangesValue *plans.ChangesSync
StateValue *states.SyncState
RefreshStateValue *states.SyncState
InstanceExpanderValue *instances.Expander
}
@ -350,6 +351,10 @@ func (ctx *BuiltinEvalContext) State() *states.SyncState {
return ctx.StateValue
}
func (ctx *BuiltinEvalContext) RefreshState() *states.SyncState {
return ctx.RefreshStateValue
}
func (ctx *BuiltinEvalContext) InstanceExpander() *instances.Expander {
return ctx.InstanceExpanderValue
}

View File

@ -126,6 +126,9 @@ type MockEvalContext struct {
StateCalled bool
StateState *states.SyncState
RefreshStateCalled bool
RefreshStateState *states.SyncState
InstanceExpanderCalled bool
InstanceExpanderExpander *instances.Expander
}
@ -338,6 +341,11 @@ func (c *MockEvalContext) State() *states.SyncState {
return c.StateState
}
func (c *MockEvalContext) RefreshState() *states.SyncState {
c.RefreshStateCalled = true
return c.RefreshStateState
}
func (c *MockEvalContext) InstanceExpander() *instances.Expander {
c.InstanceExpanderCalled = true
return c.InstanceExpanderExpander