6 "github.com/hashicorp/terraform/configs"
7 "github.com/hashicorp/terraform/dag"
10 // GraphNodeAttachResourceConfig is an interface that must be implemented by nodes
11 // that want resource configurations attached.
12 type GraphNodeAttachResourceConfig interface {
15 // Sets the configuration
16 AttachResourceConfig(*configs.Resource)
19 // AttachResourceConfigTransformer goes through the graph and attaches
20 // resource configuration structures to nodes that implement
21 // GraphNodeAttachManagedResourceConfig or GraphNodeAttachDataResourceConfig.
23 // The attached configuration structures are directly from the configuration.
24 // If they're going to be modified, a copy should be made.
25 type AttachResourceConfigTransformer struct {
26 Config *configs.Config // Config is the root node in the config tree
29 func (t *AttachResourceConfigTransformer) Transform(g *Graph) error {
31 // Go through and find GraphNodeAttachResource
32 for _, v := range g.Vertices() {
33 // Only care about GraphNodeAttachResource implementations
34 arn, ok := v.(GraphNodeAttachResourceConfig)
39 // Determine what we're looking for
40 addr := arn.ResourceAddr()
42 // Get the configuration.
43 config := t.Config.DescendentForInstance(addr.Module)
45 log.Printf("[TRACE] AttachResourceConfigTransformer: %q (%T) has no configuration available", dag.VertexName(v), v)
49 for _, r := range config.Module.ManagedResources {
52 if rAddr != addr.Resource {
53 // Not the same resource
57 log.Printf("[TRACE] AttachResourceConfigTransformer: attaching to %q (%T) config from %s", dag.VertexName(v), v, r.DeclRange)
58 arn.AttachResourceConfig(r)
60 for _, r := range config.Module.DataResources {
63 if rAddr != addr.Resource {
64 // Not the same resource
68 log.Printf("[TRACE] AttachResourceConfigTransformer: attaching to %q (%T) config from %#v", dag.VertexName(v), v, r.DeclRange)
69 arn.AttachResourceConfig(r)