fix ModulePath for nodeExpandModule
ModulePath was incorrectly returning the parent module, because it did not implement ReferenceOutside. With ReferenceOutside working correctly, we can have ModulePath return the real path and remove the special case for this during pruning.
This commit is contained in:
parent
c638252210
commit
082f91cd85
|
@ -21,9 +21,10 @@ type nodeExpandModule struct {
|
|||
}
|
||||
|
||||
var (
|
||||
_ RemovableIfNotTargeted = (*nodeExpandModule)(nil)
|
||||
_ GraphNodeEvalable = (*nodeExpandModule)(nil)
|
||||
_ GraphNodeReferencer = (*nodeExpandModule)(nil)
|
||||
_ RemovableIfNotTargeted = (*nodeExpandModule)(nil)
|
||||
_ GraphNodeEvalable = (*nodeExpandModule)(nil)
|
||||
_ GraphNodeReferencer = (*nodeExpandModule)(nil)
|
||||
_ GraphNodeReferenceOutside = (*nodeExpandModule)(nil)
|
||||
|
||||
// modules both record their expansion, and require expansion from their
|
||||
// parent modules.
|
||||
|
@ -48,7 +49,7 @@ func (n *nodeExpandModule) ModulePath() addrs.Module {
|
|||
// This node represents the module call within a module,
|
||||
// so return the CallerAddr as the path as the module
|
||||
// call may expand into multiple child instances
|
||||
return n.Addr.Parent()
|
||||
return n.Addr
|
||||
}
|
||||
|
||||
// GraphNodeReferencer implementation
|
||||
|
@ -94,6 +95,11 @@ func (n *nodeExpandModule) References() []*addrs.Reference {
|
|||
return appendResourceDestroyReferences(refs)
|
||||
}
|
||||
|
||||
// GraphNodeReferenceOutside
|
||||
func (n *nodeExpandModule) ReferenceOutside() (selfPath, referencePath addrs.Module) {
|
||||
return n.Addr, n.Addr.Parent()
|
||||
}
|
||||
|
||||
// RemovableIfNotTargeted implementation
|
||||
func (n *nodeExpandModule) RemoveIfNotTargeted() bool {
|
||||
// We need to add this so that this node will be removed if
|
||||
|
|
|
@ -187,9 +187,6 @@ func (t *pruneUnusedNodesTransformer) Transform(g *Graph) error {
|
|||
for _, v := range g.Vertices() {
|
||||
var path addrs.Module
|
||||
switch v := v.(type) {
|
||||
case instanceExpander:
|
||||
path = v.expandsInstances()
|
||||
|
||||
case GraphNodeModulePath:
|
||||
path = v.ModulePath()
|
||||
default:
|
||||
|
|
|
@ -3,6 +3,7 @@ package terraform
|
|||
import (
|
||||
"log"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
"github.com/hashicorp/terraform/configs"
|
||||
"github.com/hashicorp/terraform/dag"
|
||||
)
|
||||
|
@ -105,11 +106,22 @@ func (t *ModuleExpansionTransformer) transform(g *Graph, c *configs.Config, pare
|
|||
t.closers[c.Path.String()] = closer
|
||||
|
||||
for _, childV := range g.Vertices() {
|
||||
pather, ok := childV.(GraphNodeModulePath)
|
||||
if !ok {
|
||||
// don't connect a node to itself
|
||||
if childV == v {
|
||||
continue
|
||||
}
|
||||
if pather.ModulePath().Equal(c.Path) {
|
||||
|
||||
var path addrs.Module
|
||||
switch t := childV.(type) {
|
||||
case GraphNodeModulePath:
|
||||
path = t.ModulePath()
|
||||
case GraphNodeReferenceOutside:
|
||||
path, _ = t.ReferenceOutside()
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
if path.Equal(c.Path) {
|
||||
log.Printf("[TRACE] ModuleExpansionTransformer: %s must wait for expansion of %s", dag.VertexName(childV), c.Path)
|
||||
g.Connect(dag.BasicEdge(childV, v))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue