remove requiresInstanceExpansion
simplification allows us to settle on a single interface, graphNodeExpandsInstances for all types if instance expanders. The only other specific class of resource we need to detect during pruning is the nodeExpandApplyableResource node, which is already classified under the GraphNodeResourceInstance interface.
This commit is contained in:
parent
082f91cd85
commit
dc1b133831
|
@ -1,19 +1,7 @@
|
|||
package terraform
|
||||
|
||||
import "github.com/hashicorp/terraform/addrs"
|
||||
|
||||
// instanceExpander is implemented by nodes that causes instances to be
|
||||
// registered in the instances.Expander.
|
||||
// This is used to determine during apply whether a node is required to be in
|
||||
// the graph, by checking if it has any requiresInstanceExpansion dependents.
|
||||
// This prevents unnecessary nodes from being evaluated, and if the module is
|
||||
// being removed, we may not be able to evaluate the expansion at all.
|
||||
type instanceExpander interface {
|
||||
expandsInstances() addrs.Module
|
||||
}
|
||||
|
||||
// requiresInstanceExpansion is implemented by nodes that require their address
|
||||
// be previously registered in the instances.Expander in order to evaluate.
|
||||
type requiresInstanceExpansion interface {
|
||||
requiresExpansion()
|
||||
// graphNodeExpandsInstances is implemented by nodes that causes instances to
|
||||
// be registered in the instances.Expander.
|
||||
type graphNodeExpandsInstances interface {
|
||||
expandsInstances()
|
||||
}
|
||||
|
|
|
@ -23,15 +23,11 @@ var (
|
|||
_ GraphNodeReferencer = (*nodeExpandLocal)(nil)
|
||||
_ GraphNodeDynamicExpandable = (*nodeExpandLocal)(nil)
|
||||
_ graphNodeTemporaryValue = (*nodeExpandLocal)(nil)
|
||||
_ requiresInstanceExpansion = (*nodeExpandLocal)(nil)
|
||||
|
||||
_ graphNodeExpandsInstances = (*nodeExpandLocal)(nil)
|
||||
)
|
||||
|
||||
func (n *nodeExpandLocal) expandsInstances() addrs.Module {
|
||||
return n.Module
|
||||
}
|
||||
|
||||
// requiresInstanceExpansion implementation
|
||||
func (n *nodeExpandLocal) requiresExpansion() {}
|
||||
func (n *nodeExpandLocal) expandsInstances() {}
|
||||
|
||||
// graphNodeTemporaryValue
|
||||
func (n *nodeExpandLocal) temporaryValue() bool {
|
||||
|
|
|
@ -26,19 +26,10 @@ var (
|
|||
_ GraphNodeReferencer = (*nodeExpandModule)(nil)
|
||||
_ GraphNodeReferenceOutside = (*nodeExpandModule)(nil)
|
||||
|
||||
// modules both record their expansion, and require expansion from their
|
||||
// parent modules.
|
||||
_ requiresInstanceExpansion = (*nodeExpandModule)(nil)
|
||||
_ instanceExpander = (*nodeExpandModule)(nil)
|
||||
_ graphNodeExpandsInstances = (*nodeExpandModule)(nil)
|
||||
)
|
||||
|
||||
// requiresInstanceExpansion implementation
|
||||
func (n *nodeExpandModule) requiresExpansion() {}
|
||||
|
||||
// instanceExander implementation
|
||||
func (n *nodeExpandModule) expandsInstances() addrs.Module {
|
||||
return n.Addr
|
||||
}
|
||||
func (n *nodeExpandModule) expandsInstances() {}
|
||||
|
||||
func (n *nodeExpandModule) Name() string {
|
||||
return n.Addr.String() + " (expand)"
|
||||
|
|
|
@ -27,15 +27,11 @@ var (
|
|||
_ GraphNodeReferencer = (*nodeExpandModuleVariable)(nil)
|
||||
_ graphNodeTemporaryValue = (*nodeExpandModuleVariable)(nil)
|
||||
_ RemovableIfNotTargeted = (*nodeExpandModuleVariable)(nil)
|
||||
_ requiresInstanceExpansion = (*nodeExpandModuleVariable)(nil)
|
||||
|
||||
_ graphNodeExpandsInstances = (*nodeExpandModuleVariable)(nil)
|
||||
)
|
||||
|
||||
// requiresInstanceExpansion implementation
|
||||
func (n *nodeExpandModuleVariable) requiresExpansion() {}
|
||||
|
||||
func (n *nodeExpandModuleVariable) expandsInstances() addrs.Module {
|
||||
return n.Module
|
||||
}
|
||||
func (n *nodeExpandModuleVariable) expandsInstances() {}
|
||||
|
||||
func (n *nodeExpandModuleVariable) temporaryValue() bool {
|
||||
return true
|
||||
|
|
|
@ -24,14 +24,10 @@ var (
|
|||
_ GraphNodeReferencer = (*nodeExpandOutput)(nil)
|
||||
_ GraphNodeDynamicExpandable = (*nodeExpandOutput)(nil)
|
||||
_ graphNodeTemporaryValue = (*nodeExpandOutput)(nil)
|
||||
_ requiresInstanceExpansion = (*nodeExpandOutput)(nil)
|
||||
_ graphNodeExpandsInstances = (*nodeExpandOutput)(nil)
|
||||
)
|
||||
|
||||
func (n *nodeExpandOutput) expandsInstances() addrs.Module {
|
||||
return n.Module
|
||||
}
|
||||
|
||||
func (m *nodeExpandOutput) requiresExpansion() {}
|
||||
func (n *nodeExpandOutput) expandsInstances() {}
|
||||
|
||||
func (n *nodeExpandOutput) temporaryValue() bool {
|
||||
// this must always be evaluated if it is a root module output
|
||||
|
|
|
@ -22,19 +22,10 @@ var (
|
|||
_ GraphNodeReferencer = (*nodeExpandApplyableResource)(nil)
|
||||
_ GraphNodeConfigResource = (*nodeExpandApplyableResource)(nil)
|
||||
_ GraphNodeAttachResourceConfig = (*nodeExpandApplyableResource)(nil)
|
||||
|
||||
// Resource both expand instances and require module path expansion.
|
||||
_ requiresInstanceExpansion = (*nodeExpandApplyableResource)(nil)
|
||||
_ instanceExpander = (*nodeExpandApplyableResource)(nil)
|
||||
_ graphNodeExpandsInstances = (*nodeExpandApplyableResource)(nil)
|
||||
)
|
||||
|
||||
// requiresInstanceExpansion implementation
|
||||
func (n *nodeExpandApplyableResource) requiresExpansion() {}
|
||||
|
||||
// instanceExpander implementation
|
||||
func (n *nodeExpandApplyableResource) expandsInstances() addrs.Module {
|
||||
return n.ModulePath()
|
||||
}
|
||||
func (n *nodeExpandApplyableResource) expandsInstances() {}
|
||||
|
||||
func (n *nodeExpandApplyableResource) References() []*addrs.Reference {
|
||||
return (&NodeApplyableResource{NodeAbstractResource: n.NodeAbstractResource}).References()
|
||||
|
|
|
@ -37,12 +37,8 @@ var (
|
|||
_ GraphNodeDeposer = (*NodeApplyableResourceInstance)(nil)
|
||||
_ GraphNodeEvalable = (*NodeApplyableResourceInstance)(nil)
|
||||
_ GraphNodeAttachDependencies = (*NodeApplyableResourceInstance)(nil)
|
||||
_ requiresInstanceExpansion = (*NodeApplyableResourceInstance)(nil)
|
||||
)
|
||||
|
||||
// requiresInstanceExpansion implementation
|
||||
func (n *NodeApplyableResourceInstance) requiresExpansion() {}
|
||||
|
||||
// GraphNodeAttachDestroyer
|
||||
func (n *NodeApplyableResourceInstance) AttachDestroyNode(d GraphNodeDestroyerCBD) {
|
||||
n.destroyNode = d
|
||||
|
|
|
@ -276,11 +276,18 @@ func (m *pruneUnusedNodesMod) removeUnused(g *Graph) {
|
|||
}
|
||||
}
|
||||
|
||||
case instanceExpander:
|
||||
case graphNodeExpandsInstances:
|
||||
// Any nodes that expand instances are kept when their
|
||||
// instances may need to be evaluated.
|
||||
for _, vv := range g.UpEdges(n) {
|
||||
if _, ok := vv.(requiresInstanceExpansion); ok {
|
||||
switch vv.(type) {
|
||||
case graphNodeExpandsInstances:
|
||||
// expanders can always depend on module expansion
|
||||
// themselves
|
||||
return
|
||||
case GraphNodeResourceInstance:
|
||||
// resource instances always depend on their
|
||||
// resource node, which is an expander
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue