github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/terraform/node_resource_plan.go (about) 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 a.ResolvedProvider = n.ResolvedProvider 31 32 return &NodePlannableResourceInstance{ 33 NodeAbstractResource: a, 34 } 35 } 36 37 // The concrete resource factory we'll use for oprhans 38 concreteResourceOrphan := func(a *NodeAbstractResource) dag.Vertex { 39 // Add the config and state since we don't do that via transforms 40 a.Config = n.Config 41 a.ResolvedProvider = n.ResolvedProvider 42 43 return &NodePlannableResourceOrphan{ 44 NodeAbstractResource: a, 45 } 46 } 47 48 // Start creating the steps 49 steps := []GraphTransformer{ 50 // Expand the count. 51 &ResourceCountTransformer{ 52 Concrete: concreteResource, 53 Count: count, 54 Addr: n.ResourceAddr(), 55 }, 56 57 // Add the count orphans 58 &OrphanResourceCountTransformer{ 59 Concrete: concreteResourceOrphan, 60 Count: count, 61 Addr: n.ResourceAddr(), 62 State: state, 63 }, 64 65 // Attach the state 66 &AttachStateTransformer{State: state}, 67 68 // Targeting 69 &TargetsTransformer{ParsedTargets: n.Targets}, 70 71 // Connect references so ordering is correct 72 &ReferenceTransformer{}, 73 74 // Make sure there is a single root 75 &RootTransformer{}, 76 } 77 78 // Build the graph 79 b := &BasicGraphBuilder{ 80 Steps: steps, 81 Validate: true, 82 Name: "NodePlannableResource", 83 } 84 return b.Build(ctx.Path()) 85 }