-
Notifications
You must be signed in to change notification settings - Fork 778
/
transform_removed_modules.go
49 lines (40 loc) · 1.16 KB
/
transform_removed_modules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tofu
import (
"log"
"github.com/opentofu/opentofu/internal/addrs"
"github.com/opentofu/opentofu/internal/configs"
"github.com/opentofu/opentofu/internal/states"
)
// RemovedModuleTransformer implements GraphTransformer to add nodes indicating
// when a module was removed from the configuration.
type RemovedModuleTransformer struct {
Config *configs.Config // root node in the config tree
State *states.State
}
func (t *RemovedModuleTransformer) Transform(g *Graph) error {
// nothing to remove if there's no state!
if t.State == nil {
return nil
}
removed := map[string]addrs.Module{}
for _, m := range t.State.Modules {
cc := t.Config.DescendentForInstance(m.Addr)
if cc != nil {
continue
}
removed[m.Addr.Module().String()] = m.Addr.Module()
log.Printf("[DEBUG] %s is no longer in configuration\n", m.Addr)
}
// add closers to collect any module instances we're removing
for _, modAddr := range removed {
closer := &nodeCloseModule{
Addr: modAddr,
}
g.Add(closer)
}
return nil
}