From 35e087fe5b54b869f5dbbafe8bd0282e16db76c9 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 3 May 2019 16:40:02 -0400 Subject: [PATCH] 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. --- terraform/node_resource_plan_instance.go | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/terraform/node_resource_plan_instance.go b/terraform/node_resource_plan_instance.go index d69472f82..75e0bcd34 100644 --- a/terraform/node_resource_plan_instance.go +++ b/terraform/node_resource_plan_instance.go @@ -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 },