only add nodes in RemovedModuleTransformer
Let the ReferenceTransformer connect them once it's fixed.
This commit is contained in:
parent
5915d883d2
commit
3916f3a5a3
|
@ -2,12 +2,12 @@ package terraform
|
|||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/config/module"
|
||||
"github.com/hashicorp/terraform/dag"
|
||||
)
|
||||
|
||||
// RemoveModuleTransformer implements GraphTransformer to add nodes indicating
|
||||
// when a module was removed from the configuration.
|
||||
type RemovedModuleTransformer struct {
|
||||
Module *module.Tree // root module
|
||||
State *State
|
||||
|
@ -19,17 +19,6 @@ func (t *RemovedModuleTransformer) Transform(g *Graph) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// get a map of all nodes by path, so we can connect anything that might be
|
||||
// in the module
|
||||
refMap := map[string][]dag.Vertex{}
|
||||
for _, v := range g.Vertices() {
|
||||
if pn, ok := v.(GraphNodeSubPath); ok {
|
||||
path := normalizeModulePath(pn.Path())[1:]
|
||||
p := modulePrefixStr(path)
|
||||
refMap[p] = append(refMap[p], v)
|
||||
}
|
||||
}
|
||||
|
||||
for _, m := range t.State.Modules {
|
||||
c := t.Module.Child(m.Path[1:])
|
||||
if c != nil {
|
||||
|
@ -37,19 +26,7 @@ func (t *RemovedModuleTransformer) Transform(g *Graph) error {
|
|||
}
|
||||
|
||||
log.Printf("[DEBUG] module %s no longer in config\n", modulePrefixStr(m.Path))
|
||||
|
||||
node := &NodeModuleRemoved{PathValue: m.Path}
|
||||
g.Add(node)
|
||||
|
||||
// connect this to anything that contains the module's path
|
||||
refPath := modulePrefixStr(m.Path)
|
||||
for p, nodes := range refMap {
|
||||
if strings.HasPrefix(p, refPath) {
|
||||
for _, parent := range nodes {
|
||||
g.Connect(dag.BasicEdge(node, parent))
|
||||
}
|
||||
}
|
||||
}
|
||||
g.Add(&NodeModuleRemoved{PathValue: m.Path})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue