attach dependencies during plan

This was previously done during refresh alone, now we need to insert
these during the refresh portion of plan.
This commit is contained in:
James Bardin 2020-09-21 15:53:53 -04:00
parent c3182bd589
commit 8105096ec8
4 changed files with 23 additions and 6 deletions

View File

@ -549,12 +549,7 @@ func (n *EvalRefreshDependencies) Eval(ctx EvalContext) (interface{}, error) {
return nil, nil
}
depMap := make(map[string]addrs.ConfigResource)
for _, d := range *n.Dependencies {
depMap[d.String()] = d
}
// We have already dependencies in state, so we need to trust those for
// We already have dependencies in state, so we need to trust those for
// refresh. We can't write out new dependencies until apply time in case
// the configuration has been changed in a manner the conflicts with the
// stored dependencies.
@ -563,6 +558,11 @@ func (n *EvalRefreshDependencies) Eval(ctx EvalContext) (interface{}, error) {
return nil, nil
}
depMap := make(map[string]addrs.ConfigResource)
for _, d := range *n.Dependencies {
depMap[d.String()] = d
}
deps := make([]addrs.ConfigResource, 0, len(depMap))
for _, d := range depMap {
deps = append(deps, d)

View File

@ -146,6 +146,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
// Connect so that the references are ready for targeting. We'll
// have to connect again later for providers and so on.
&ReferenceTransformer{},
&AttachDependenciesTransformer{},
// Make sure data sources are aware of any depends_on from the
// configuration

View File

@ -20,6 +20,10 @@ type nodeExpandPlannableResource struct {
// during graph construction, if dependencies require us to force this
// on regardless of what the configuration says.
ForceCreateBeforeDestroy *bool
// We attach dependencies to the Resource during refresh, since the
// instances are instantiated during DynamicExpand.
dependencies []addrs.ConfigResource
}
var (
@ -29,6 +33,7 @@ var (
_ GraphNodeReferencer = (*nodeExpandPlannableResource)(nil)
_ GraphNodeConfigResource = (*nodeExpandPlannableResource)(nil)
_ GraphNodeAttachResourceConfig = (*nodeExpandPlannableResource)(nil)
_ GraphNodeAttachDependencies = (*nodeExpandPlannableResource)(nil)
_ GraphNodeTargetable = (*nodeExpandPlannableResource)(nil)
)
@ -36,6 +41,11 @@ func (n *nodeExpandPlannableResource) Name() string {
return n.NodeAbstractResource.Name() + " (expand)"
}
// GraphNodeAttachDependencies
func (n *nodeExpandPlannableResource) AttachDependencies(deps []addrs.ConfigResource) {
n.dependencies = deps
}
// GraphNodeDestroyerCBD
func (n *nodeExpandPlannableResource) CreateBeforeDestroy() bool {
if n.ForceCreateBeforeDestroy != nil {
@ -71,6 +81,7 @@ func (n *nodeExpandPlannableResource) DynamicExpand(ctx EvalContext) (*Graph, er
NodeAbstractResource: n.NodeAbstractResource,
Addr: resAddr,
ForceCreateBeforeDestroy: n.ForceCreateBeforeDestroy,
dependencies: n.dependencies,
})
}
@ -101,6 +112,7 @@ func (n *nodeExpandPlannableResource) DynamicExpand(ctx EvalContext) (*Graph, er
a.Schema = n.Schema
a.ProvisionerSchemas = n.ProvisionerSchemas
a.ProviderMetas = n.ProviderMetas
a.Dependencies = n.dependencies
return &NodePlannableResourceInstanceOrphan{
NodeAbstractResourceInstance: a,
@ -131,6 +143,8 @@ type NodePlannableResource struct {
// during graph construction, if dependencies require us to force this
// on regardless of what the configuration says.
ForceCreateBeforeDestroy *bool
dependencies []addrs.ConfigResource
}
var (
@ -220,6 +234,7 @@ func (n *NodePlannableResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
a.ProvisionerSchemas = n.ProvisionerSchemas
a.ProviderMetas = n.ProviderMetas
a.dependsOn = n.dependsOn
a.Dependencies = n.dependencies
return &NodePlannableResourceInstance{
NodeAbstractResourceInstance: a,

View File

@ -160,6 +160,7 @@ func (n *NodePlannableResourceInstance) evalTreeManagedResource(addr addrs.AbsRe
State: &instanceRefreshState,
ProviderSchema: &providerSchema,
targetState: refreshState,
Dependencies: &n.Dependencies,
},
// Plan the instance