diff --git a/terraform/instance_expanders.go b/terraform/instance_expanders.go index 7dd5496a0..b3733afb0 100644 --- a/terraform/instance_expanders.go +++ b/terraform/instance_expanders.go @@ -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() } diff --git a/terraform/node_local.go b/terraform/node_local.go index d0a15c7ff..06651de20 100644 --- a/terraform/node_local.go +++ b/terraform/node_local.go @@ -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 { diff --git a/terraform/node_module_expand.go b/terraform/node_module_expand.go index 676a23049..99827f428 100644 --- a/terraform/node_module_expand.go +++ b/terraform/node_module_expand.go @@ -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)" diff --git a/terraform/node_module_variable.go b/terraform/node_module_variable.go index 6d16ef90a..063ab201e 100644 --- a/terraform/node_module_variable.go +++ b/terraform/node_module_variable.go @@ -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 diff --git a/terraform/node_output.go b/terraform/node_output.go index 75e438986..ef5e6cd5e 100644 --- a/terraform/node_output.go +++ b/terraform/node_output.go @@ -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 diff --git a/terraform/node_resource_apply.go b/terraform/node_resource_apply.go index b4de20c01..d02dc09c8 100644 --- a/terraform/node_resource_apply.go +++ b/terraform/node_resource_apply.go @@ -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() diff --git a/terraform/node_resource_apply_instance.go b/terraform/node_resource_apply_instance.go index 45fa33ccf..1282f8a11 100644 --- a/terraform/node_resource_apply_instance.go +++ b/terraform/node_resource_apply_instance.go @@ -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 diff --git a/terraform/transform_destroy_edge.go b/terraform/transform_destroy_edge.go index 226a0162e..8532e0907 100644 --- a/terraform/transform_destroy_edge.go +++ b/terraform/transform_destroy_edge.go @@ -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 } }