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