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.go95
1 files changed, 88 insertions, 7 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 6ab9df7..cd4fe92 100644
--- a/vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go
+++ b/vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go
@@ -45,13 +45,6 @@ func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph,
45 Addr: n.ResourceAddr(), 45 Addr: n.ResourceAddr(),
46 }, 46 },
47 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 48 // Add the count orphans to make sure these resources are accounted for
56 // during a scale in. 49 // during a scale in.
57 &OrphanResourceCountTransformer{ 50 &OrphanResourceCountTransformer{
@@ -100,6 +93,9 @@ func (n *NodeRefreshableManagedResourceInstance) EvalTree() EvalNode {
100 // Eval info is different depending on what kind of resource this is 93 // Eval info is different depending on what kind of resource this is
101 switch mode := n.Addr.Mode; mode { 94 switch mode := n.Addr.Mode; mode {
102 case config.ManagedResourceMode: 95 case config.ManagedResourceMode:
96 if n.ResourceState == nil {
97 return n.evalTreeManagedResourceNoState()
98 }
103 return n.evalTreeManagedResource() 99 return n.evalTreeManagedResource()
104 100
105 case config.DataResourceMode: 101 case config.DataResourceMode:
@@ -176,3 +172,88 @@ func (n *NodeRefreshableManagedResourceInstance) evalTreeManagedResource() EvalN
176 }, 172 },
177 } 173 }
178} 174}
175
176// evalTreeManagedResourceNoState produces an EvalSequence for refresh resource
177// nodes that don't have state attached. An example of where this functionality
178// is useful is when a resource that already exists in state is being scaled
179// out, ie: has its resource count increased. In this case, the scaled out node
180// needs to be available to other nodes (namely data sources) that may depend
181// on it for proper interpolation, or confusing "index out of range" errors can
182// occur.
183//
184// The steps in this sequence are very similar to the steps carried out in
185// plan, but nothing is done with the diff after it is created - it is dropped,
186// and its changes are not counted in the UI.
187func (n *NodeRefreshableManagedResourceInstance) evalTreeManagedResourceNoState() EvalNode {
188 // Declare a bunch of variables that are used for state during
189 // evaluation. Most of this are written to by-address below.
190 var provider ResourceProvider
191 var state *InstanceState
192 var resourceConfig *ResourceConfig
193
194 addr := n.NodeAbstractResource.Addr
195 stateID := addr.stateId()
196 info := &InstanceInfo{
197 Id: stateID,
198 Type: addr.Type,
199 ModulePath: normalizeModulePath(addr.Path),
200 }
201
202 // Build the resource for eval
203 resource := &Resource{
204 Name: addr.Name,
205 Type: addr.Type,
206 CountIndex: addr.Index,
207 }
208 if resource.CountIndex < 0 {
209 resource.CountIndex = 0
210 }
211
212 // Determine the dependencies for the state.
213 stateDeps := n.StateReferences()
214
215 return &EvalSequence{
216 Nodes: []EvalNode{
217 &EvalInterpolate{
218 Config: n.Config.RawConfig.Copy(),
219 Resource: resource,
220 Output: &resourceConfig,
221 },
222 &EvalGetProvider{
223 Name: n.ProvidedBy()[0],
224 Output: &provider,
225 },
226 // Re-run validation to catch any errors we missed, e.g. type
227 // mismatches on computed values.
228 &EvalValidateResource{
229 Provider: &provider,
230 Config: &resourceConfig,
231 ResourceName: n.Config.Name,
232 ResourceType: n.Config.Type,
233 ResourceMode: n.Config.Mode,
234 IgnoreWarnings: true,
235 },
236 &EvalReadState{
237 Name: stateID,
238 Output: &state,
239 },
240 &EvalDiff{
241 Name: stateID,
242 Info: info,
243 Config: &resourceConfig,
244 Resource: n.Config,
245 Provider: &provider,
246 State: &state,
247 OutputState: &state,
248 Stub: true,
249 },
250 &EvalWriteState{
251 Name: stateID,
252 ResourceType: n.Config.Type,
253 Provider: n.Config.Provider,
254 Dependencies: stateDeps,
255 State: &state,
256 },
257 },
258 }
259}