github.com/aspring/terraform@v0.8.2-0.20161216122603-6a8619a5db2e/terraform/graph_builder_plan.go (about) 1 package terraform 2 3 import ( 4 "github.com/hashicorp/terraform/config/module" 5 "github.com/hashicorp/terraform/dag" 6 ) 7 8 // PlanGraphBuilder implements GraphBuilder and is responsible for building 9 // a graph for planning (creating a Terraform Diff). 10 // 11 // The primary difference between this graph and others: 12 // 13 // * Based on the config since it represents the target state 14 // 15 // * Ignores lifecycle options since no lifecycle events occur here. This 16 // simplifies the graph significantly since complex transforms such as 17 // create-before-destroy can be completely ignored. 18 // 19 type PlanGraphBuilder struct { 20 // Module is the root module for the graph to build. 21 Module *module.Tree 22 23 // State is the current state 24 State *State 25 26 // Providers is the list of providers supported. 27 Providers []string 28 29 // Targets are resources to target 30 Targets []string 31 32 // DisableReduce, if true, will not reduce the graph. Great for testing. 33 DisableReduce bool 34 35 // Validate will do structural validation of the graph. 36 Validate bool 37 } 38 39 // See GraphBuilder 40 func (b *PlanGraphBuilder) Build(path []string) (*Graph, error) { 41 return (&BasicGraphBuilder{ 42 Steps: b.Steps(), 43 Validate: b.Validate, 44 Name: "PlanGraphBuilder", 45 }).Build(path) 46 } 47 48 // See GraphBuilder 49 func (b *PlanGraphBuilder) Steps() []GraphTransformer { 50 // Custom factory for creating providers. 51 concreteProvider := func(a *NodeAbstractProvider) dag.Vertex { 52 return &NodeApplyableProvider{ 53 NodeAbstractProvider: a, 54 } 55 } 56 57 concreteResource := func(a *NodeAbstractResource) dag.Vertex { 58 return &NodePlannableResource{ 59 NodeAbstractResource: a, 60 } 61 } 62 63 concreteResourceOrphan := func(a *NodeAbstractResource) dag.Vertex { 64 return &NodePlannableResourceOrphan{ 65 NodeAbstractResource: a, 66 } 67 } 68 69 steps := []GraphTransformer{ 70 // Creates all the resources represented in the config 71 &ConfigTransformer{ 72 Concrete: concreteResource, 73 Module: b.Module, 74 }, 75 76 // Add the outputs 77 &OutputTransformer{Module: b.Module}, 78 79 // Add orphan resources 80 &OrphanResourceTransformer{ 81 Concrete: concreteResourceOrphan, 82 State: b.State, 83 Module: b.Module, 84 }, 85 86 // Attach the configuration to any resources 87 &AttachResourceConfigTransformer{Module: b.Module}, 88 89 // Attach the state 90 &AttachStateTransformer{State: b.State}, 91 92 // Add root variables 93 &RootVariableTransformer{Module: b.Module}, 94 95 // Create all the providers 96 &MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider}, 97 &ProviderTransformer{}, 98 &DisableProviderTransformer{}, 99 &ParentProviderTransformer{}, 100 &AttachProviderConfigTransformer{Module: b.Module}, 101 102 // Add module variables 103 &ModuleVariableTransformer{Module: b.Module}, 104 105 // Connect so that the references are ready for targeting. We'll 106 // have to connect again later for providers and so on. 107 &ReferenceTransformer{}, 108 109 // Target 110 &TargetsTransformer{Targets: b.Targets}, 111 112 // Single root 113 &RootTransformer{}, 114 } 115 116 if !b.DisableReduce { 117 // Perform the transitive reduction to make our graph a bit 118 // more sane if possible (it usually is possible). 119 steps = append(steps, &TransitiveReductionTransformer{}) 120 } 121 122 return steps 123 }