Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 09242fa

Browse files
committed
terraform: remove legacy graph builder
1 parent a9d799c commit 09242fa

5 files changed

Lines changed: 17 additions & 496 deletions

File tree

command/graph.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ Options:
158158
-no-color If specified, output won't contain any color.
159159
160160
-type=plan Type of graph to output. Can be: plan, plan-destroy, apply,
161-
legacy.
161+
validate, input, refresh.
162+
162163
163164
`
164165
return strings.TrimSpace(helpText)

helper/experiment/experiment.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ import (
5050
// of definition and use. This allows the compiler to enforce references
5151
// so it becomes easy to remove the features.
5252
var (
53-
// Reuse the old graphs from TF 0.7.x. These will be removed at some point.
54-
X_legacyGraph = newBasicID("legacy-graph", "LEGACY_GRAPH", false)
55-
5653
// Shadow graph. This is already on by default. Disabling it will be
5754
// allowed for awhile in order for it to not block operations.
5855
X_shadow = newBasicID("shadow", "SHADOW", true)
@@ -75,7 +72,6 @@ var (
7572
func init() {
7673
// The list of all experiments, update this when an experiment is added.
7774
All = []ID{
78-
X_legacyGraph,
7975
X_shadow,
8076
x_force,
8177
}

terraform/context.go

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,11 @@ func (c *Context) Graph(typ GraphType, opts *ContextGraphOpts) (*Graph, error) {
262262
Targets: c.targets,
263263
Validate: opts.Validate,
264264
}).Build(RootModulePath)
265-
266-
case GraphTypeLegacy:
267-
return c.graphBuilder(opts).Build(RootModulePath)
268265
}
269266

270267
return nil, fmt.Errorf("unknown graph type: %s", typ)
271268
}
272269

273-
// GraphBuilder returns the GraphBuilder that will be used to create
274-
// the graphs for this context.
275-
func (c *Context) graphBuilder(g *ContextGraphOpts) GraphBuilder {
276-
return &BuiltinGraphBuilder{
277-
Root: c.module,
278-
Diff: c.diff,
279-
Providers: c.components.ResourceProviders(),
280-
Provisioners: c.components.ResourceProvisioners(),
281-
State: c.state,
282-
Targets: c.targets,
283-
Destroy: c.destroy,
284-
Validate: g.Validate,
285-
Verbose: g.Verbose,
286-
}
287-
}
288-
289270
// ShadowError returns any errors caught during a shadow operation.
290271
//
291272
// A shadow operation is an operation run in parallel to a real operation
@@ -465,15 +446,8 @@ func (c *Context) Apply() (*State, error) {
465446
// Copy our own state
466447
c.state = c.state.DeepCopy()
467448

468-
// Enable the new graph by default
469-
X_legacyGraph := experiment.Enabled(experiment.X_legacyGraph)
470-
471449
// Build the graph.
472-
graphType := GraphTypeLegacy
473-
if !X_legacyGraph {
474-
graphType = GraphTypeApply
475-
}
476-
graph, err := c.Graph(graphType, nil)
450+
graph, err := c.Graph(GraphTypeApply, nil)
477451
if err != nil {
478452
return nil, err
479453
}
@@ -541,17 +515,10 @@ func (c *Context) Plan() (*Plan, error) {
541515
c.diff.init()
542516
c.diffLock.Unlock()
543517

544-
// Used throughout below
545-
X_legacyGraph := experiment.Enabled(experiment.X_legacyGraph)
546-
547518
// Build the graph.
548-
graphType := GraphTypeLegacy
549-
if !X_legacyGraph {
550-
if c.destroy {
551-
graphType = GraphTypePlanDestroy
552-
} else {
553-
graphType = GraphTypePlan
554-
}
519+
graphType := GraphTypePlan
520+
if c.destroy {
521+
graphType = GraphTypePlanDestroy
555522
}
556523
graph, err := c.Graph(graphType, nil)
557524
if err != nil {
@@ -576,15 +543,17 @@ func (c *Context) Plan() (*Plan, error) {
576543
p.Diff.DeepCopy()
577544
}
578545

579-
// We don't do the reverification during the new destroy plan because
580-
// it will use a different apply process.
581-
if X_legacyGraph {
582-
// Now that we have a diff, we can build the exact graph that Apply will use
583-
// and catch any possible cycles during the Plan phase.
584-
if _, err := c.Graph(GraphTypeLegacy, nil); err != nil {
585-
return nil, err
546+
/*
547+
// We don't do the reverification during the new destroy plan because
548+
// it will use a different apply process.
549+
if X_legacyGraph {
550+
// Now that we have a diff, we can build the exact graph that Apply will use
551+
// and catch any possible cycles during the Plan phase.
552+
if _, err := c.Graph(GraphTypeLegacy, nil); err != nil {
553+
return nil, err
554+
}
586555
}
587-
}
556+
*/
588557

589558
var errs error
590559
if len(walker.ValidationErrors) > 0 {
@@ -606,15 +575,8 @@ func (c *Context) Refresh() (*State, error) {
606575
// Copy our own state
607576
c.state = c.state.DeepCopy()
608577

609-
// Used throughout below
610-
X_legacyGraph := experiment.Enabled(experiment.X_legacyGraph)
611-
612578
// Build the graph.
613-
graphType := GraphTypeLegacy
614-
if !X_legacyGraph {
615-
graphType = GraphTypeRefresh
616-
}
617-
graph, err := c.Graph(graphType, nil)
579+
graph, err := c.Graph(GraphTypeRefresh, nil)
618580
if err != nil {
619581
return nil, err
620582
}

terraform/graph_builder.go

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"log"
66
"strings"
7-
8-
"github.com/hashicorp/terraform/config/module"
97
)
108

119
// GraphBuilder is an interface that can be implemented and used with
@@ -77,160 +75,3 @@ func (b *BasicGraphBuilder) Build(path []string) (*Graph, error) {
7775

7876
return g, nil
7977
}
80-
81-
// BuiltinGraphBuilder is responsible for building the complete graph that
82-
// Terraform uses for execution. It is an opinionated builder that defines
83-
// the step order required to build a complete graph as is used and expected
84-
// by Terraform.
85-
//
86-
// If you require a custom graph, you'll have to build it up manually
87-
// on your own by building a new GraphBuilder implementation.
88-
type BuiltinGraphBuilder struct {
89-
// Root is the root module of the graph to build.
90-
Root *module.Tree
91-
92-
// Diff is the diff. The proper module diffs will be looked up.
93-
Diff *Diff
94-
95-
// State is the global state. The proper module states will be looked
96-
// up by graph path.
97-
State *State
98-
99-
// Providers is the list of providers supported.
100-
Providers []string
101-
102-
// Provisioners is the list of provisioners supported.
103-
Provisioners []string
104-
105-
// Targets is the user-specified list of resources to target.
106-
Targets []string
107-
108-
// Destroy is set to true when we're in a `terraform destroy` or a
109-
// `terraform plan -destroy`
110-
Destroy bool
111-
112-
// Determines whether the GraphBuilder should perform graph validation before
113-
// returning the Graph. Generally you want this to be done, except when you'd
114-
// like to inspect a problematic graph.
115-
Validate bool
116-
117-
// Verbose is set to true when the graph should be built "worst case",
118-
// skipping any prune steps. This is used for early cycle detection during
119-
// Validate and for manual inspection via `terraform graph -verbose`.
120-
Verbose bool
121-
}
122-
123-
// Build builds the graph according to the steps returned by Steps.
124-
func (b *BuiltinGraphBuilder) Build(path []string) (*Graph, error) {
125-
basic := &BasicGraphBuilder{
126-
Steps: b.Steps(path),
127-
Validate: b.Validate,
128-
Name: "BuiltinGraphBuilder",
129-
}
130-
131-
return basic.Build(path)
132-
}
133-
134-
// Steps returns the ordered list of GraphTransformers that must be executed
135-
// to build a complete graph.
136-
func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
137-
steps := []GraphTransformer{
138-
// Create all our resources from the configuration and state
139-
&ConfigTransformerOld{Module: b.Root},
140-
&OrphanTransformer{
141-
State: b.State,
142-
Module: b.Root,
143-
},
144-
145-
// Output-related transformations
146-
&AddOutputOrphanTransformer{State: b.State},
147-
148-
// Provider-related transformations
149-
&MissingProviderTransformer{Providers: b.Providers},
150-
&ProviderTransformer{},
151-
&DisableProviderTransformerOld{},
152-
153-
// Provisioner-related transformations
154-
&MissingProvisionerTransformer{Provisioners: b.Provisioners},
155-
&ProvisionerTransformer{},
156-
157-
// Run our vertex-level transforms
158-
&VertexTransformer{
159-
Transforms: []GraphVertexTransformer{
160-
// Expand any statically expanded nodes, such as module graphs
161-
&ExpandTransform{
162-
Builder: b,
163-
},
164-
},
165-
},
166-
167-
// Flatten stuff
168-
&FlattenTransformer{},
169-
170-
// Make sure all the connections that are proxies are connected through
171-
&ProxyTransformer{},
172-
}
173-
174-
// If we're on the root path, then we do a bunch of other stuff.
175-
// We don't do the following for modules.
176-
if len(path) <= 1 {
177-
steps = append(steps,
178-
// Optionally reduces the graph to a user-specified list of targets and
179-
// their dependencies.
180-
&TargetsTransformer{Targets: b.Targets, Destroy: b.Destroy},
181-
182-
// Create orphan output nodes
183-
&OrphanOutputTransformer{Module: b.Root, State: b.State},
184-
185-
// Prune the providers. This must happen only once because flattened
186-
// modules might depend on empty providers.
187-
&PruneProviderTransformer{},
188-
189-
// Create the destruction nodes
190-
&DestroyTransformer{FullDestroy: b.Destroy},
191-
b.conditional(&conditionalOpts{
192-
If: func() bool { return !b.Destroy },
193-
Then: &CreateBeforeDestroyTransformer{},
194-
}),
195-
b.conditional(&conditionalOpts{
196-
If: func() bool { return !b.Verbose },
197-
Then: &PruneDestroyTransformer{Diff: b.Diff, State: b.State},
198-
}),
199-
200-
// Remove the noop nodes
201-
&PruneNoopTransformer{Diff: b.Diff, State: b.State},
202-
203-
// Insert nodes to close opened plugin connections
204-
&CloseProviderTransformer{},
205-
&CloseProvisionerTransformer{},
206-
207-
// Perform the transitive reduction to make our graph a bit
208-
// more sane if possible (it usually is possible).
209-
&TransitiveReductionTransformer{},
210-
)
211-
}
212-
213-
// Make sure we have a single root
214-
steps = append(steps, &RootTransformer{})
215-
216-
// Remove nils
217-
for i, s := range steps {
218-
if s == nil {
219-
steps = append(steps[:i], steps[i+1:]...)
220-
}
221-
}
222-
223-
return steps
224-
}
225-
226-
type conditionalOpts struct {
227-
If func() bool
228-
Then GraphTransformer
229-
}
230-
231-
func (b *BuiltinGraphBuilder) conditional(o *conditionalOpts) GraphTransformer {
232-
if o.If != nil && o.Then != nil && o.If() {
233-
return o.Then
234-
}
235-
return nil
236-
}

0 commit comments

Comments
 (0)