always load data source state during refresh

We need to load the state during refresh, so that even if the data
source can't be read due to `depends_on`, the state can be saved back
again to prevent it from being lost altogether.

This is a step towards having data sources refresh like resources, which
will be from their saved state value.
This commit is contained in:
James Bardin 2020-05-04 21:49:05 -04:00
parent 23e259a68c
commit 0f5dab4838
1 changed files with 3 additions and 13 deletions

View File

@ -205,15 +205,11 @@ func (n *NodeRefreshableDataResourceInstance) EvalTree() EvalNode {
Schema: &providerSchema,
},
// Always destroy the existing state first, since we must
// make sure that values from a previous read will not
// get interpolated if we end up needing to defer our
// loading until apply time.
&EvalWriteState{
&EvalReadState{
Addr: addr.Resource,
ProviderAddr: n.ResolvedProvider,
State: &state, // a pointer to nil, here
Provider: &provider,
ProviderSchema: &providerSchema,
Output: &state,
},
// EvalReadData will _attempt_ to read the data source, but may
@ -229,12 +225,6 @@ func (n *NodeRefreshableDataResourceInstance) EvalTree() EvalNode {
OutputChange: &change,
OutputConfigValue: &configVal,
OutputState: &state,
// If the config explicitly has a depends_on for this data
// source, assume the intention is to prevent refreshing ahead
// of that dependency, and therefore we need to deal with this
// resource during the apply phase. We do that by forcing this
// read to result in a plan.
ForcePlanRead: len(n.Config.DependsOn) > 0,
},
&EvalIf{