6 "github.com/hashicorp/terraform/dag"
9 // GraphNodeAttachResourceState is an interface that can be implemented
10 // to request that a ResourceState is attached to the node.
11 type GraphNodeAttachResourceState interface {
12 // The address to the resource for the state
13 ResourceAddr() *ResourceAddress
16 AttachResourceState(*ResourceState)
19 // AttachStateTransformer goes through the graph and attaches
20 // state to nodes that implement the interfaces above.
21 type AttachStateTransformer struct {
22 State *State // State is the root state
25 func (t *AttachStateTransformer) Transform(g *Graph) error {
26 // If no state, then nothing to do
28 log.Printf("[DEBUG] Not attaching any state: state is nil")
32 filter := &StateFilter{State: t.State}
33 for _, v := range g.Vertices() {
34 // Only care about nodes requesting we're adding state
35 an, ok := v.(GraphNodeAttachResourceState)
39 addr := an.ResourceAddr()
41 // Get the module state
42 results, err := filter.Filter(addr.String())
47 // Attach the first resource state we get
49 for _, result := range results {
50 if rs, ok := result.Value.(*ResourceState); ok {
52 "[DEBUG] Attaching resource state to %q: %#v",
53 dag.VertexName(v), rs)
54 an.AttachResourceState(rs)
62 "[DEBUG] Resource state not found for %q: %s",
63 dag.VertexName(v), addr)