only add nodes in RemovedModuleTransformer

Let the ReferenceTransformer connect them once it's fixed.
This commit is contained in:
James Bardin 2017-11-09 10:32:01 -05:00
parent 5915d883d2
commit 3916f3a5a3
1 changed files with 3 additions and 26 deletions

View File

@ -2,12 +2,12 @@ package terraform
import ( import (
"log" "log"
"strings"
"github.com/hashicorp/terraform/config/module" "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 { type RemovedModuleTransformer struct {
Module *module.Tree // root module Module *module.Tree // root module
State *State State *State
@ -19,17 +19,6 @@ func (t *RemovedModuleTransformer) Transform(g *Graph) error {
return nil 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 { for _, m := range t.State.Modules {
c := t.Module.Child(m.Path[1:]) c := t.Module.Child(m.Path[1:])
if c != nil { 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)) log.Printf("[DEBUG] module %s no longer in config\n", modulePrefixStr(m.Path))
g.Add(&NodeModuleRemoved{PathValue: 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))
}
}
}
} }
return nil return nil
} }