mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-11 08:05:33 -06:00
add dependsOn to evalDataRead
this is also needed during refresh, so move it into the base struct type
This commit is contained in:
parent
58babccc7a
commit
535267e986
@ -52,6 +52,12 @@ type evalReadData struct {
|
|||||||
// - If planned action is plans.Update, it indicates that the data source
|
// - 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.
|
// was read, and the result needs to be stored in state during apply.
|
||||||
OutputChange **plans.ResourceInstanceChange
|
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.
|
// 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
|
// 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
|
// in the config, they we be discovered in plan and the data source will be
|
||||||
// read again.
|
// read again.
|
||||||
if !configKnown || (priorVal.IsNull() && len(n.Config.DependsOn) > 0) {
|
if !configKnown || (priorVal.IsNull() && n.forcePlanRead()) {
|
||||||
if configKnown {
|
if configKnown {
|
||||||
log.Printf("[TRACE] evalReadDataRefresh: %s configuration is fully known, but we're forcing a read plan to be created", absAddr)
|
log.Printf("[TRACE] evalReadDataRefresh: %s configuration is fully known, but we're forcing a read plan to be created", absAddr)
|
||||||
} else {
|
} else {
|
||||||
@ -291,3 +297,10 @@ func (n *evalReadDataRefresh) Eval(ctx EvalContext) (interface{}, error) {
|
|||||||
|
|
||||||
return nil, diags.ErrWithWarnings()
|
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
|
||||||
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/zclconf/go-cty/cty"
|
"github.com/zclconf/go-cty/cty"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/addrs"
|
|
||||||
"github.com/hashicorp/terraform/plans"
|
"github.com/hashicorp/terraform/plans"
|
||||||
"github.com/hashicorp/terraform/plans/objchange"
|
"github.com/hashicorp/terraform/plans/objchange"
|
||||||
"github.com/hashicorp/terraform/states"
|
"github.com/hashicorp/terraform/states"
|
||||||
@ -18,12 +17,6 @@ import (
|
|||||||
// or generating a plan to do so.
|
// or generating a plan to do so.
|
||||||
type evalReadDataPlan struct {
|
type evalReadDataPlan struct {
|
||||||
evalReadData
|
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) {
|
func (n *evalReadDataPlan) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
|
@ -171,6 +171,7 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer {
|
|||||||
// have to connect again later for providers and so on.
|
// have to connect again later for providers and so on.
|
||||||
&ReferenceTransformer{},
|
&ReferenceTransformer{},
|
||||||
&AttachDependenciesTransformer{},
|
&AttachDependenciesTransformer{},
|
||||||
|
&attachDataResourceDependenciesTransformer{},
|
||||||
|
|
||||||
// Target
|
// Target
|
||||||
&TargetsTransformer{
|
&TargetsTransformer{
|
||||||
|
@ -121,6 +121,7 @@ func (n *NodeRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, er
|
|||||||
a.Config = n.Config
|
a.Config = n.Config
|
||||||
a.ResolvedProvider = n.ResolvedProvider
|
a.ResolvedProvider = n.ResolvedProvider
|
||||||
a.ProviderMetas = n.ProviderMetas
|
a.ProviderMetas = n.ProviderMetas
|
||||||
|
a.dependsOn = n.dependsOn
|
||||||
|
|
||||||
return &NodeRefreshableDataResourceInstance{
|
return &NodeRefreshableDataResourceInstance{
|
||||||
NodeAbstractResourceInstance: a,
|
NodeAbstractResourceInstance: a,
|
||||||
@ -227,6 +228,7 @@ func (n *NodeRefreshableDataResourceInstance) EvalTree() EvalNode {
|
|||||||
ProviderSchema: &providerSchema,
|
ProviderSchema: &providerSchema,
|
||||||
OutputChange: &change,
|
OutputChange: &change,
|
||||||
State: &state,
|
State: &state,
|
||||||
|
dependsOn: n.dependsOn,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ func (n *NodePlannableResourceInstance) evalTreeDataResource(addr addrs.AbsResou
|
|||||||
ProviderSchema: &providerSchema,
|
ProviderSchema: &providerSchema,
|
||||||
OutputChange: &change,
|
OutputChange: &change,
|
||||||
State: &state,
|
State: &state,
|
||||||
|
dependsOn: n.dependsOn,
|
||||||
},
|
},
|
||||||
dependsOn: n.dependsOn,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
&EvalWriteState{
|
&EvalWriteState{
|
||||||
|
Loading…
Reference in New Issue
Block a user