github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/transform_removed_modules.go (about) 1 package terraform 2 3 import ( 4 "log" 5 6 "github.com/hashicorp/terraform-plugin-sdk/internal/configs" 7 "github.com/hashicorp/terraform-plugin-sdk/internal/states" 8 ) 9 10 // RemovedModuleTransformer implements GraphTransformer to add nodes indicating 11 // when a module was removed from the configuration. 12 type RemovedModuleTransformer struct { 13 Config *configs.Config // root node in the config tree 14 State *states.State 15 } 16 17 func (t *RemovedModuleTransformer) Transform(g *Graph) error { 18 // nothing to remove if there's no state! 19 if t.State == nil { 20 return nil 21 } 22 23 for _, m := range t.State.Modules { 24 cc := t.Config.DescendentForInstance(m.Addr) 25 if cc != nil { 26 continue 27 } 28 29 log.Printf("[DEBUG] %s is no longer in configuration\n", m.Addr) 30 g.Add(&NodeModuleRemoved{Addr: m.Addr}) 31 } 32 return nil 33 }