From d6a586709cf8eee53b46b56bcf00fa7fa44d6441 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 4 Sep 2020 15:53:15 -0400 Subject: [PATCH] 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. --- terraform/eval_context.go | 5 +++++ terraform/eval_context_builtin.go | 5 +++++ terraform/eval_context_mock.go | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/terraform/eval_context.go b/terraform/eval_context.go index 1448ae93de..6c8a5d9d16 100644 --- a/terraform/eval_context.go +++ b/terraform/eval_context.go @@ -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. diff --git a/terraform/eval_context_builtin.go b/terraform/eval_context_builtin.go index efb88b3103..17e84de6e5 100644 --- a/terraform/eval_context_builtin.go +++ b/terraform/eval_context_builtin.go @@ -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 } diff --git a/terraform/eval_context_mock.go b/terraform/eval_context_mock.go index f97c3d08cd..11ae6941f5 100644 --- a/terraform/eval_context_mock.go +++ b/terraform/eval_context_mock.go @@ -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