2016-09-13 12:56:37 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/terraform/config/module"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ApplyGraphBuilder implements GraphBuilder and is responsible for building
|
|
|
|
// a graph for applying a Terraform diff.
|
|
|
|
//
|
|
|
|
// Because the graph is built from the diff (vs. the config or state),
|
|
|
|
// this helps ensure that the apply-time graph doesn't modify any resources
|
|
|
|
// that aren't explicitly in the diff. There are other scenarios where the
|
|
|
|
// diff can be deviated, so this is just one layer of protection.
|
|
|
|
type ApplyGraphBuilder struct {
|
2016-09-14 13:44:41 -05:00
|
|
|
// Module is the root module for the graph to build.
|
|
|
|
Module *module.Tree
|
2016-09-13 12:56:37 -05:00
|
|
|
|
|
|
|
// Diff is the diff to apply.
|
|
|
|
Diff *Diff
|
|
|
|
|
2016-09-13 19:52:09 -05:00
|
|
|
// State is the current state
|
|
|
|
State *State
|
|
|
|
|
2016-09-13 12:56:37 -05:00
|
|
|
// Providers is the list of providers supported.
|
|
|
|
Providers []string
|
|
|
|
|
|
|
|
// Provisioners is the list of provisioners supported.
|
|
|
|
Provisioners []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// See GraphBuilder
|
|
|
|
func (b *ApplyGraphBuilder) Build(path []string) (*Graph, error) {
|
|
|
|
return (&BasicGraphBuilder{
|
|
|
|
Steps: b.Steps(),
|
|
|
|
Validate: true,
|
|
|
|
}).Build(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
// See GraphBuilder
|
|
|
|
func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
|
2016-09-15 01:58:16 -05:00
|
|
|
// Custom factory for creating providers.
|
|
|
|
providerFactory := func(name string, path []string) GraphNodeProvider {
|
|
|
|
return &NodeApplyableProvider{
|
|
|
|
NameValue: name,
|
|
|
|
PathValue: path,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-13 12:56:37 -05:00
|
|
|
steps := []GraphTransformer{
|
|
|
|
// Creates all the nodes represented in the diff.
|
2016-09-13 19:52:09 -05:00
|
|
|
&DiffTransformer{
|
|
|
|
Diff: b.Diff,
|
2016-09-14 13:44:41 -05:00
|
|
|
Module: b.Module,
|
2016-09-13 19:52:09 -05:00
|
|
|
State: b.State,
|
|
|
|
},
|
2016-09-13 16:34:15 -05:00
|
|
|
|
2016-09-18 23:45:19 -05:00
|
|
|
// Create orphan output nodes
|
|
|
|
&OrphanOutputTransformer{Module: b.Module, State: b.State},
|
|
|
|
|
2016-09-20 12:23:48 -05:00
|
|
|
// Attach the configuration to any resources
|
|
|
|
&AttachResourceConfigTransformer{Module: b.Module},
|
|
|
|
|
2016-09-16 22:26:10 -05:00
|
|
|
// Attach the state
|
|
|
|
&AttachStateTransformer{State: b.State},
|
|
|
|
|
2016-09-20 12:23:48 -05:00
|
|
|
// Destruction ordering
|
|
|
|
&DestroyEdgeTransformer{Module: b.Module, State: b.State},
|
|
|
|
|
2016-09-13 19:11:34 -05:00
|
|
|
// Create all the providers
|
2016-09-15 01:58:16 -05:00
|
|
|
&MissingProviderTransformer{Providers: b.Providers, Factory: providerFactory},
|
2016-09-13 19:11:34 -05:00
|
|
|
&ProviderTransformer{},
|
2016-09-14 16:43:14 -05:00
|
|
|
&ParentProviderTransformer{},
|
2016-09-16 18:30:29 -05:00
|
|
|
&AttachProviderConfigTransformer{Module: b.Module},
|
2016-09-13 19:11:34 -05:00
|
|
|
|
2016-09-15 11:32:37 -05:00
|
|
|
// Provisioner-related transformations
|
|
|
|
&MissingProvisionerTransformer{Provisioners: b.Provisioners},
|
|
|
|
&ProvisionerTransformer{},
|
|
|
|
|
2016-09-16 16:36:35 -05:00
|
|
|
// Add root variables
|
|
|
|
&RootVariableTransformer{Module: b.Module},
|
|
|
|
|
2016-09-16 15:56:10 -05:00
|
|
|
// Add module variables
|
2016-09-16 16:00:21 -05:00
|
|
|
&ModuleVariableTransformer{Module: b.Module},
|
2016-09-16 15:56:10 -05:00
|
|
|
|
2016-09-16 01:20:35 -05:00
|
|
|
// Add the outputs
|
|
|
|
&OutputTransformer{Module: b.Module},
|
|
|
|
|
2016-09-15 20:30:11 -05:00
|
|
|
// Connect references so ordering is correct
|
|
|
|
&ReferenceTransformer{},
|
|
|
|
|
2016-09-19 11:28:24 -05:00
|
|
|
// Add the node to fix the state count boundaries
|
|
|
|
&CountBoundaryTransformer{},
|
|
|
|
|
2016-09-13 16:34:15 -05:00
|
|
|
// Single root
|
|
|
|
&RootTransformer{},
|
2016-09-19 11:28:24 -05:00
|
|
|
|
|
|
|
// Perform the transitive reduction to make our graph a bit
|
|
|
|
// more sane if possible (it usually is possible).
|
|
|
|
&TransitiveReductionTransformer{},
|
2016-09-13 12:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return steps
|
|
|
|
}
|