diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/node_resource_plan.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/terraform/node_resource_plan.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/node_resource_plan.go b/vendor/github.com/hashicorp/terraform/terraform/node_resource_plan.go new file mode 100644 index 0000000..52bbf88 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/terraform/node_resource_plan.go | |||
@@ -0,0 +1,83 @@ | |||
1 | package terraform | ||
2 | |||
3 | import ( | ||
4 | "github.com/hashicorp/terraform/dag" | ||
5 | ) | ||
6 | |||
7 | // NodePlannableResource represents a resource that is "plannable": | ||
8 | // it is ready to be planned in order to create a diff. | ||
9 | type NodePlannableResource struct { | ||
10 | *NodeAbstractCountResource | ||
11 | } | ||
12 | |||
13 | // GraphNodeDynamicExpandable | ||
14 | func (n *NodePlannableResource) DynamicExpand(ctx EvalContext) (*Graph, error) { | ||
15 | // Grab the state which we read | ||
16 | state, lock := ctx.State() | ||
17 | lock.RLock() | ||
18 | defer lock.RUnlock() | ||
19 | |||
20 | // Expand the resource count which must be available by now from EvalTree | ||
21 | count, err := n.Config.Count() | ||
22 | if err != nil { | ||
23 | return nil, err | ||
24 | } | ||
25 | |||
26 | // The concrete resource factory we'll use | ||
27 | concreteResource := func(a *NodeAbstractResource) dag.Vertex { | ||
28 | // Add the config and state since we don't do that via transforms | ||
29 | a.Config = n.Config | ||
30 | |||
31 | return &NodePlannableResourceInstance{ | ||
32 | NodeAbstractResource: a, | ||
33 | } | ||
34 | } | ||
35 | |||
36 | // The concrete resource factory we'll use for oprhans | ||
37 | concreteResourceOrphan := func(a *NodeAbstractResource) dag.Vertex { | ||
38 | // Add the config and state since we don't do that via transforms | ||
39 | a.Config = n.Config | ||
40 | |||
41 | return &NodePlannableResourceOrphan{ | ||
42 | NodeAbstractResource: a, | ||
43 | } | ||
44 | } | ||
45 | |||
46 | // Start creating the steps | ||
47 | steps := []GraphTransformer{ | ||
48 | // Expand the count. | ||
49 | &ResourceCountTransformer{ | ||
50 | Concrete: concreteResource, | ||
51 | Count: count, | ||
52 | Addr: n.ResourceAddr(), | ||
53 | }, | ||
54 | |||
55 | // Add the count orphans | ||
56 | &OrphanResourceCountTransformer{ | ||
57 | Concrete: concreteResourceOrphan, | ||
58 | Count: count, | ||
59 | Addr: n.ResourceAddr(), | ||
60 | State: state, | ||
61 | }, | ||
62 | |||
63 | // Attach the state | ||
64 | &AttachStateTransformer{State: state}, | ||
65 | |||
66 | // Targeting | ||
67 | &TargetsTransformer{ParsedTargets: n.Targets}, | ||
68 | |||
69 | // Connect references so ordering is correct | ||
70 | &ReferenceTransformer{}, | ||
71 | |||
72 | // Make sure there is a single root | ||
73 | &RootTransformer{}, | ||
74 | } | ||
75 | |||
76 | // Build the graph | ||
77 | b := &BasicGraphBuilder{ | ||
78 | Steps: steps, | ||
79 | Validate: true, | ||
80 | Name: "NodePlannableResource", | ||
81 | } | ||
82 | return b.Build(ctx.Path()) | ||
83 | } | ||