7 "github.com/hashicorp/terraform/config"
8 "github.com/hashicorp/terraform/config/module"
11 // GraphNodeAttachResourceConfig is an interface that must be implemented by nodes
12 // that want resource configurations attached.
13 type GraphNodeAttachResourceConfig interface {
14 // ResourceAddr is the address to the resource
15 ResourceAddr() *ResourceAddress
17 // Sets the configuration
18 AttachResourceConfig(*config.Resource)
21 // AttachResourceConfigTransformer goes through the graph and attaches
22 // resource configuration structures to nodes that implement the interfaces
25 // The attached configuration structures are directly from the configuration.
26 // If they're going to be modified, a copy should be made.
27 type AttachResourceConfigTransformer struct {
28 Module *module.Tree // Module is the root module for the config
31 func (t *AttachResourceConfigTransformer) Transform(g *Graph) error {
32 log.Printf("[TRACE] AttachResourceConfigTransformer: Beginning...")
34 // Go through and find GraphNodeAttachResource
35 for _, v := range g.Vertices() {
36 // Only care about GraphNodeAttachResource implementations
37 arn, ok := v.(GraphNodeAttachResourceConfig)
42 // Determine what we're looking for
43 addr := arn.ResourceAddr()
45 "[TRACE] AttachResourceConfigTransformer: Attach resource "+
46 "config request: %s", addr)
48 // Get the configuration.
49 path := normalizeModulePath(addr.Path)
51 tree := t.Module.Child(path)
56 // Go through the resource configs to find the matching config
57 for _, r := range tree.Config().Resources {
58 // Get a resource address so we can compare
59 a, err := parseResourceAddressConfig(r)
62 "Error parsing config address, this is a bug: %#v", r))
66 // If this is not the same resource, then continue
71 log.Printf("[TRACE] Attaching resource config: %#v", r)
72 arn.AttachResourceConfig(r)