mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
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 (
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user