From ad22e137e6aad7b5c3aa442e8aaaaef77384a4b1 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 4 Sep 2020 15:59:22 -0400 Subject: [PATCH] Get the new RefreshState into the right contexts --- terraform/context.go | 34 ++++++++++++++++++++++----------- terraform/graph_walk_context.go | 2 ++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/terraform/context.go b/terraform/context.go index 4156aa1f0..8afba75cd 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -781,20 +781,32 @@ func (c *Context) walk(graph *Graph, operation walkOperation) (*ContextGraphWalk } func (c *Context) graphWalker(operation walkOperation) *ContextGraphWalker { - if operation == walkValidate { - return &ContextGraphWalker{ - Context: c, - State: states.NewState().SyncWrapper(), - Changes: c.changes.SyncWrapper(), - InstanceExpander: instances.NewExpander(), - Operation: operation, - StopContext: c.runContext, - RootVariableValues: c.variables, - } + var state *states.SyncState + var refreshState *states.SyncState + + switch operation { + case walkValidate: + // validate should not use any state + s := states.NewState() + state = s.SyncWrapper() + + // validate currently uses the plan graph, so we have to populate the + // refreshState. + refreshState = s.SyncWrapper() + + case walkPlan: + state = c.state.SyncWrapper() + // plan requires a second state to store the refreshed resources + refreshState = c.state.DeepCopy().SyncWrapper() + + default: + state = c.state.SyncWrapper() } + return &ContextGraphWalker{ Context: c, - State: c.state.SyncWrapper(), + State: state, + RefreshState: refreshState, Changes: c.changes.SyncWrapper(), InstanceExpander: instances.NewExpander(), Operation: operation, diff --git a/terraform/graph_walk_context.go b/terraform/graph_walk_context.go index c842c0af4..d3ca73b3f 100644 --- a/terraform/graph_walk_context.go +++ b/terraform/graph_walk_context.go @@ -26,6 +26,7 @@ type ContextGraphWalker struct { // Configurable values Context *Context State *states.SyncState // Used for safe concurrent access to state + RefreshState *states.SyncState // Used for safe concurrent access to state Changes *plans.ChangesSync // Used for safe concurrent writes to changes InstanceExpander *instances.Expander // Tracks our gradual expansion of module and resource instances Operation walkOperation @@ -96,6 +97,7 @@ func (w *ContextGraphWalker) EvalContext() EvalContext { ProvisionerLock: &w.provisionerLock, ChangesValue: w.Changes, StateValue: w.State, + RefreshStateValue: w.RefreshState, Evaluator: evaluator, VariableValues: w.variableValues, VariableValuesLock: &w.variableValuesLock,