7 "github.com/hashicorp/terraform/dag"
10 // StateTransformer is a GraphTransformer that adds the elements of
11 // the state to the graph.
13 // This transform is used for example by the DestroyPlanGraphBuilder to ensure
14 // that only resources that are in the state are represented in the graph.
15 type StateTransformer struct {
16 Concrete ConcreteResourceNodeFunc
21 func (t *StateTransformer) Transform(g *Graph) error {
22 // If the state is nil or empty (nil is empty) then do nothing
27 // Go through all the modules in the diff.
28 log.Printf("[TRACE] StateTransformer: starting")
29 var nodes []dag.Vertex
30 for _, ms := range t.State.Modules {
31 log.Printf("[TRACE] StateTransformer: Module: %v", ms.Path)
33 // Go through all the resources in this module.
34 for name, rs := range ms.Resources {
35 log.Printf("[TRACE] StateTransformer: Resource %q: %#v", name, rs)
37 // Add the resource to the graph
38 addr, err := parseResourceAddressInternal(name)
41 "Error parsing internal name, this is a bug: %q", name))
44 // Very important: add the module path for this resource to
45 // the address. Remove "root" from it.
46 addr.Path = ms.Path[1:]
48 // Add the resource to the graph
49 abstract := &NodeAbstractResource{Addr: addr}
50 var node dag.Vertex = abstract
51 if f := t.Concrete; f != nil {
55 nodes = append(nodes, node)
59 // Add all the nodes to the graph
60 for _, n := range nodes {