]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/terraform/terraform/node_resource_refresh.go
Transfer of provider code
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / node_resource_refresh.go
index 3a44926cef76d51c8d32795403b2539996ffdd65..6ab9df7a26f8a2b6f2edb91487858ea475a11ce7 100644 (file)
@@ -4,21 +4,99 @@ import (
        "fmt"
 
        "github.com/hashicorp/terraform/config"
+       "github.com/hashicorp/terraform/dag"
 )
 
-// NodeRefreshableResource represents a resource that is "applyable":
+// NodeRefreshableManagedResource represents a resource that is expanabled into
+// NodeRefreshableManagedResourceInstance. Resource count orphans are also added.
+type NodeRefreshableManagedResource struct {
+       *NodeAbstractCountResource
+}
+
+// GraphNodeDynamicExpandable
+func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
+       // Grab the state which we read
+       state, lock := ctx.State()
+       lock.RLock()
+       defer lock.RUnlock()
+
+       // Expand the resource count which must be available by now from EvalTree
+       count, err := n.Config.Count()
+       if err != nil {
+               return nil, err
+       }
+
+       // The concrete resource factory we'll use
+       concreteResource := func(a *NodeAbstractResource) dag.Vertex {
+               // Add the config and state since we don't do that via transforms
+               a.Config = n.Config
+
+               return &NodeRefreshableManagedResourceInstance{
+                       NodeAbstractResource: a,
+               }
+       }
+
+       // Start creating the steps
+       steps := []GraphTransformer{
+               // Expand the count.
+               &ResourceCountTransformer{
+                       Concrete: concreteResource,
+                       Count:    count,
+                       Addr:     n.ResourceAddr(),
+               },
+
+               // Switch up any node missing state to a plannable resource. This helps
+               // catch cases where data sources depend on the counts from this resource
+               // during a scale out.
+               &ResourceRefreshPlannableTransformer{
+                       State: state,
+               },
+
+               // Add the count orphans to make sure these resources are accounted for
+               // during a scale in.
+               &OrphanResourceCountTransformer{
+                       Concrete: concreteResource,
+                       Count:    count,
+                       Addr:     n.ResourceAddr(),
+                       State:    state,
+               },
+
+               // Attach the state
+               &AttachStateTransformer{State: state},
+
+               // Targeting
+               &TargetsTransformer{ParsedTargets: n.Targets},
+
+               // Connect references so ordering is correct
+               &ReferenceTransformer{},
+
+               // Make sure there is a single root
+               &RootTransformer{},
+       }
+
+       // Build the graph
+       b := &BasicGraphBuilder{
+               Steps:    steps,
+               Validate: true,
+               Name:     "NodeRefreshableManagedResource",
+       }
+
+       return b.Build(ctx.Path())
+}
+
+// NodeRefreshableManagedResourceInstance represents a resource that is "applyable":
 // it is ready to be applied and is represented by a diff.
-type NodeRefreshableResource struct {
+type NodeRefreshableManagedResourceInstance struct {
        *NodeAbstractResource
 }
 
 // GraphNodeDestroyer
-func (n *NodeRefreshableResource) DestroyAddr() *ResourceAddress {
+func (n *NodeRefreshableManagedResourceInstance) DestroyAddr() *ResourceAddress {
        return n.Addr
 }
 
 // GraphNodeEvalable
-func (n *NodeRefreshableResource) EvalTree() EvalNode {
+func (n *NodeRefreshableManagedResourceInstance) EvalTree() EvalNode {
        // Eval info is different depending on what kind of resource this is
        switch mode := n.Addr.Mode; mode {
        case config.ManagedResourceMode:
@@ -44,7 +122,7 @@ func (n *NodeRefreshableResource) EvalTree() EvalNode {
        }
 }
 
-func (n *NodeRefreshableResource) evalTreeManagedResource() EvalNode {
+func (n *NodeRefreshableManagedResourceInstance) evalTreeManagedResource() EvalNode {
        addr := n.NodeAbstractResource.Addr
 
        // stateId is the ID to put into the state