always re-read datasource if there are dep changes

If a datasource's dependencies have planned changes, then we need to
plan a read for the data source, because the config may change once the
dependencies have been applied.
This commit is contained in:
James Bardin 2019-05-03 16:40:02 -04:00
parent f9dfa98533
commit 35e087fe5b
1 changed files with 25 additions and 2 deletions

View File

@ -81,8 +81,31 @@ func (n *NodePlannableResourceInstance) evalTreeDataResource(addr addrs.AbsResou
// here.
&EvalIf{
If: func(ctx EvalContext) (bool, error) {
if state != nil && state.Status != states.ObjectPlanned {
return true, EvalEarlyExitError{}
depChanges := false
// Check and see if any of our dependencies have changes.
changes := ctx.Changes()
for _, d := range n.StateReferences() {
ri, ok := d.(addrs.ResourceInstance)
if !ok {
continue
}
change := changes.GetResourceInstanceChange(ri.Absolute(ctx.Path()), states.CurrentGen)
if change != nil && change.Action != plans.NoOp {
depChanges = true
break
}
}
refreshed := state != nil && state.Status != states.ObjectPlanned
// If there are no dependency changes, and it's not a forced
// read because we there was no Refresh, then we don't need
// to re-read. If any dependencies have changes, it means
// our config may also have changes and we need to Read the
// data source again.
if !depChanges && refreshed {
return false, EvalEarlyExitError{}
}
return true, nil
},