aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go88
1 files changed, 83 insertions, 5 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go b/vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go
index 3a44926..6ab9df7 100644
--- a/vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go
+++ b/vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go
@@ -4,21 +4,99 @@ import (
4 "fmt" 4 "fmt"
5 5
6 "github.com/hashicorp/terraform/config" 6 "github.com/hashicorp/terraform/config"
7 "github.com/hashicorp/terraform/dag"
7) 8)
8 9
9// NodeRefreshableResource represents a resource that is "applyable": 10// NodeRefreshableManagedResource represents a resource that is expanabled into
11// NodeRefreshableManagedResourceInstance. Resource count orphans are also added.
12type NodeRefreshableManagedResource struct {
13 *NodeAbstractCountResource
14}
15
16// GraphNodeDynamicExpandable
17func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
18 // Grab the state which we read
19 state, lock := ctx.State()
20 lock.RLock()
21 defer lock.RUnlock()
22
23 // Expand the resource count which must be available by now from EvalTree
24 count, err := n.Config.Count()
25 if err != nil {
26 return nil, err
27 }
28
29 // The concrete resource factory we'll use
30 concreteResource := func(a *NodeAbstractResource) dag.Vertex {
31 // Add the config and state since we don't do that via transforms
32 a.Config = n.Config
33
34 return &NodeRefreshableManagedResourceInstance{
35 NodeAbstractResource: a,
36 }
37 }
38
39 // Start creating the steps
40 steps := []GraphTransformer{
41 // Expand the count.
42 &ResourceCountTransformer{
43 Concrete: concreteResource,
44 Count: count,
45 Addr: n.ResourceAddr(),
46 },
47
48 // Switch up any node missing state to a plannable resource. This helps
49 // catch cases where data sources depend on the counts from this resource
50 // during a scale out.
51 &ResourceRefreshPlannableTransformer{
52 State: state,
53 },
54
55 // Add the count orphans to make sure these resources are accounted for
56 // during a scale in.
57 &OrphanResourceCountTransformer{
58 Concrete: concreteResource,
59 Count: count,
60 Addr: n.ResourceAddr(),
61 State: state,
62 },
63
64 // Attach the state
65 &AttachStateTransformer{State: state},
66
67 // Targeting
68 &TargetsTransformer{ParsedTargets: n.Targets},
69
70 // Connect references so ordering is correct
71 &ReferenceTransformer{},
72
73 // Make sure there is a single root
74 &RootTransformer{},
75 }
76
77 // Build the graph
78 b := &BasicGraphBuilder{
79 Steps: steps,
80 Validate: true,
81 Name: "NodeRefreshableManagedResource",
82 }
83
84 return b.Build(ctx.Path())
85}
86
87// NodeRefreshableManagedResourceInstance represents a resource that is "applyable":
10// it is ready to be applied and is represented by a diff. 88// it is ready to be applied and is represented by a diff.
11type NodeRefreshableResource struct { 89type NodeRefreshableManagedResourceInstance struct {
12 *NodeAbstractResource 90 *NodeAbstractResource
13} 91}
14 92
15// GraphNodeDestroyer 93// GraphNodeDestroyer
16func (n *NodeRefreshableResource) DestroyAddr() *ResourceAddress { 94func (n *NodeRefreshableManagedResourceInstance) DestroyAddr() *ResourceAddress {
17 return n.Addr 95 return n.Addr
18} 96}
19 97
20// GraphNodeEvalable 98// GraphNodeEvalable
21func (n *NodeRefreshableResource) EvalTree() EvalNode { 99func (n *NodeRefreshableManagedResourceInstance) EvalTree() EvalNode {
22 // Eval info is different depending on what kind of resource this is 100 // Eval info is different depending on what kind of resource this is
23 switch mode := n.Addr.Mode; mode { 101 switch mode := n.Addr.Mode; mode {
24 case config.ManagedResourceMode: 102 case config.ManagedResourceMode:
@@ -44,7 +122,7 @@ func (n *NodeRefreshableResource) EvalTree() EvalNode {
44 } 122 }
45} 123}
46 124
47func (n *NodeRefreshableResource) evalTreeManagedResource() EvalNode { 125func (n *NodeRefreshableManagedResourceInstance) evalTreeManagedResource() EvalNode {
48 addr := n.NodeAbstractResource.Addr 126 addr := n.NodeAbstractResource.Addr
49 127
50 // stateId is the ID to put into the state 128 // stateId is the ID to put into the state