add dependsOn to evalDataRead

this is also needed during refresh, so move it into the base struct type
This commit is contained in:
James Bardin 2020-06-03 19:44:43 -04:00
parent 58babccc7a
commit 535267e986
5 changed files with 18 additions and 9 deletions

View File

@ -52,6 +52,12 @@ type evalReadData struct {
// - If planned action is plans.Update, it indicates that the data source
// was read, and the result needs to be stored in state during apply.
OutputChange **plans.ResourceInstanceChange
// dependsOn stores the list of transitive resource addresses that any
// configuration depends_on references may resolve to. This is used to
// determine if there are any changes that will force this data sources to
// be deferred to apply.
dependsOn []addrs.ConfigResource
}
// readDataSource handles everything needed to call ReadDataSource on the provider.
@ -235,7 +241,7 @@ func (n *evalReadDataRefresh) Eval(ctx EvalContext) (interface{}, error) {
// refresh, that we can read this resource. If there are dependency updates
// in the config, they we be discovered in plan and the data source will be
// read again.
if !configKnown || (priorVal.IsNull() && len(n.Config.DependsOn) > 0) {
if !configKnown || (priorVal.IsNull() && n.forcePlanRead()) {
if configKnown {
log.Printf("[TRACE] evalReadDataRefresh: %s configuration is fully known, but we're forcing a read plan to be created", absAddr)
} else {
@ -291,3 +297,10 @@ func (n *evalReadDataRefresh) Eval(ctx EvalContext) (interface{}, error) {
return nil, diags.ErrWithWarnings()
}
// forcePlanRead determines if we need to override the usual behavior of
// immediately reading from the data source where possible, instead forcing us
// to generate a plan.
func (n *evalReadDataRefresh) forcePlanRead() bool {
return len(n.Config.DependsOn) > 0 || len(n.dependsOn) > 0
}

View File

@ -6,7 +6,6 @@ import (
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/plans"
"github.com/hashicorp/terraform/plans/objchange"
"github.com/hashicorp/terraform/states"
@ -18,12 +17,6 @@ import (
// or generating a plan to do so.
type evalReadDataPlan struct {
evalReadData
// dependsOn stores the list of transitive resource addresses that any
// configuration depends_on references may resolve to. This is used to
// determine if there are any changes that will force this data sources to
// be deferred to apply.
dependsOn []addrs.ConfigResource
}
func (n *evalReadDataPlan) Eval(ctx EvalContext) (interface{}, error) {

View File

@ -171,6 +171,7 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer {
// have to connect again later for providers and so on.
&ReferenceTransformer{},
&AttachDependenciesTransformer{},
&attachDataResourceDependenciesTransformer{},
// Target
&TargetsTransformer{

View File

@ -121,6 +121,7 @@ func (n *NodeRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, er
a.Config = n.Config
a.ResolvedProvider = n.ResolvedProvider
a.ProviderMetas = n.ProviderMetas
a.dependsOn = n.dependsOn
return &NodeRefreshableDataResourceInstance{
NodeAbstractResourceInstance: a,
@ -227,6 +228,7 @@ func (n *NodeRefreshableDataResourceInstance) EvalTree() EvalNode {
ProviderSchema: &providerSchema,
OutputChange: &change,
State: &state,
dependsOn: n.dependsOn,
},
},

View File

@ -83,8 +83,8 @@ func (n *NodePlannableResourceInstance) evalTreeDataResource(addr addrs.AbsResou
ProviderSchema: &providerSchema,
OutputChange: &change,
State: &state,
dependsOn: n.dependsOn,
},
dependsOn: n.dependsOn,
},
&EvalWriteState{