audit graph builder to make them more similar

Auditing the graph builder to remove unused transformers (planning does
not need to close provisioners for example), and re-order them. While
many of the transformations are commutative, using the same order
ensures the same behavior between operations when the commutative
property is lost or changed.
This commit is contained in:
James Bardin 2020-10-06 17:39:53 -04:00
parent a32028aeed
commit 35714e61e6
6 changed files with 41 additions and 79 deletions

View File

@ -87,6 +87,12 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
Config: b.Config, Config: b.Config,
}, },
// Add dynamic values
&RootVariableTransformer{Config: b.Config},
&ModuleVariableTransformer{Config: b.Config},
&LocalTransformer{Config: b.Config},
&OutputTransformer{Config: b.Config},
// Creates all the resource instances represented in the diff, along // Creates all the resource instances represented in the diff, along
// with dependency edges against the whole-resource nodes added by // with dependency edges against the whole-resource nodes added by
// ConfigTransformer above. // ConfigTransformer above.
@ -96,31 +102,19 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
Changes: b.Changes, Changes: b.Changes,
}, },
// Attach the state
&AttachStateTransformer{State: b.State},
// Create orphan output nodes // Create orphan output nodes
&OrphanOutputTransformer{Config: b.Config, State: b.State}, &OrphanOutputTransformer{Config: b.Config, State: b.State},
// Attach the configuration to any resources // Attach the configuration to any resources
&AttachResourceConfigTransformer{Config: b.Config}, &AttachResourceConfigTransformer{Config: b.Config},
// Attach the state
&AttachStateTransformer{State: b.State},
// Provisioner-related transformations // Provisioner-related transformations
&MissingProvisionerTransformer{Provisioners: b.Components.ResourceProvisioners()}, &MissingProvisionerTransformer{Provisioners: b.Components.ResourceProvisioners()},
&ProvisionerTransformer{}, &ProvisionerTransformer{},
// Add root variables
&RootVariableTransformer{Config: b.Config},
// Add the local values
&LocalTransformer{Config: b.Config},
// Add the outputs
&OutputTransformer{Config: b.Config},
// Add module variables
&ModuleVariableTransformer{Config: b.Config},
// add providers // add providers
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config), TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
@ -150,7 +144,6 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
State: b.State, State: b.State,
Schemas: b.Schemas, Schemas: b.Schemas,
}, },
&CBDEdgeTransformer{ &CBDEdgeTransformer{
Config: b.Config, Config: b.Config,
State: b.State, State: b.State,

View File

@ -92,8 +92,13 @@ func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer {
// created proper destroy ordering. // created proper destroy ordering.
&TargetsTransformer{Targets: b.Targets}, &TargetsTransformer{Targets: b.Targets},
// Close opened plugin connections
&CloseProviderTransformer{},
// Close the root module // Close the root module
&CloseRootModuleTransformer{}, &CloseRootModuleTransformer{},
&TransitiveReductionTransformer{},
} }
return steps return steps

View File

@ -60,28 +60,20 @@ func (b *EvalGraphBuilder) Steps() []GraphTransformer {
// Creates all the data resources that aren't in the state. This will also // Creates all the data resources that aren't in the state. This will also
// add any orphans from scaling in as destroy nodes. // add any orphans from scaling in as destroy nodes.
&ConfigTransformer{ &ConfigTransformer{
Concrete: nil, // just use the abstract type Config: b.Config,
Config: b.Config,
Unique: true,
}, },
// Attach the state // Add dynamic values
&AttachStateTransformer{State: b.State}, &RootVariableTransformer{Config: b.Config},
&ModuleVariableTransformer{Config: b.Config},
&LocalTransformer{Config: b.Config},
&OutputTransformer{Config: b.Config},
// Attach the configuration to any resources // Attach the configuration to any resources
&AttachResourceConfigTransformer{Config: b.Config}, &AttachResourceConfigTransformer{Config: b.Config},
// Add root variables // Attach the state
&RootVariableTransformer{Config: b.Config}, &AttachStateTransformer{State: b.State},
// Add the local values
&LocalTransformer{Config: b.Config},
// Add the outputs
&OutputTransformer{Config: b.Config},
// Add module variables
&ModuleVariableTransformer{Config: b.Config},
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config), TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
@ -92,9 +84,7 @@ func (b *EvalGraphBuilder) Steps() []GraphTransformer {
// Create expansion nodes for all of the module calls. This must // Create expansion nodes for all of the module calls. This must
// come after all other transformers that create nodes representing // come after all other transformers that create nodes representing
// objects that can belong to modules. // objects that can belong to modules.
&ModuleExpansionTransformer{ &ModuleExpansionTransformer{Config: b.Config},
Config: b.Config,
},
// Connect so that the references are ready for targeting. We'll // Connect so that the references are ready for targeting. We'll
// have to connect again later for providers and so on. // have to connect again later for providers and so on.

View File

@ -55,26 +55,20 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
// Create all our resources from the configuration and state // Create all our resources from the configuration and state
&ConfigTransformer{Config: config}, &ConfigTransformer{Config: config},
// Add dynamic values
&RootVariableTransformer{Config: b.Config},
&ModuleVariableTransformer{Config: b.Config},
&LocalTransformer{Config: b.Config},
&OutputTransformer{Config: b.Config},
// Attach the configuration to any resources // Attach the configuration to any resources
&AttachResourceConfigTransformer{Config: b.Config}, &AttachResourceConfigTransformer{Config: b.Config},
// Add the import steps // Add the import steps
&ImportStateTransformer{Targets: b.ImportTargets, Config: b.Config}, &ImportStateTransformer{Targets: b.ImportTargets, Config: b.Config},
// Add root variables
&RootVariableTransformer{Config: b.Config},
TransformProviders(b.Components.ResourceProviders(), concreteProvider, config), TransformProviders(b.Components.ResourceProviders(), concreteProvider, config),
// Add the local values
&LocalTransformer{Config: b.Config},
// Add the outputs
&OutputTransformer{Config: b.Config},
// Add module variables
&ModuleVariableTransformer{Config: b.Config},
// Must attach schemas before ReferenceTransformer so that we can // Must attach schemas before ReferenceTransformer so that we can
// analyze the configuration to find references. // analyze the configuration to find references.
&AttachSchemaTransformer{Schemas: b.Schemas, Config: b.Config}, &AttachSchemaTransformer{Schemas: b.Schemas, Config: b.Config},
@ -82,9 +76,7 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
// Create expansion nodes for all of the module calls. This must // Create expansion nodes for all of the module calls. This must
// come after all other transformers that create nodes representing // come after all other transformers that create nodes representing
// objects that can belong to modules. // objects that can belong to modules.
&ModuleExpansionTransformer{ &ModuleExpansionTransformer{Config: b.Config},
Config: b.Config,
},
// Connect so that the references are ready for targeting. We'll // Connect so that the references are ready for targeting. We'll
// have to connect again later for providers and so on. // have to connect again later for providers and so on.

View File

@ -84,10 +84,10 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
Config: b.Config, Config: b.Config,
}, },
// Add the local values // Add dynamic values
&RootVariableTransformer{Config: b.Config},
&ModuleVariableTransformer{Config: b.Config},
&LocalTransformer{Config: b.Config}, &LocalTransformer{Config: b.Config},
// Add the outputs
&OutputTransformer{Config: b.Config}, &OutputTransformer{Config: b.Config},
// Add orphan resources // Add orphan resources
@ -106,29 +106,20 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
State: b.State, State: b.State,
}, },
// Attach the state
&AttachStateTransformer{State: b.State},
// Create orphan output nodes // Create orphan output nodes
&OrphanOutputTransformer{ &OrphanOutputTransformer{Config: b.Config, State: b.State},
Config: b.Config,
State: b.State,
},
// Attach the configuration to any resources // Attach the configuration to any resources
&AttachResourceConfigTransformer{Config: b.Config}, &AttachResourceConfigTransformer{Config: b.Config},
// Attach the state // Provisioner-related transformations
&AttachStateTransformer{State: b.State},
// Add root variables
&RootVariableTransformer{Config: b.Config},
&MissingProvisionerTransformer{Provisioners: b.Components.ResourceProvisioners()}, &MissingProvisionerTransformer{Provisioners: b.Components.ResourceProvisioners()},
&ProvisionerTransformer{}, &ProvisionerTransformer{},
// Add module variables // add providers
&ModuleVariableTransformer{
Config: b.Config,
},
TransformProviders(b.Components.ResourceProviders(), b.ConcreteProvider, b.Config), TransformProviders(b.Components.ResourceProviders(), b.ConcreteProvider, b.Config),
// Remove modules no longer present in the config // Remove modules no longer present in the config
@ -141,10 +132,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
// Create expansion nodes for all of the module calls. This must // Create expansion nodes for all of the module calls. This must
// come after all other transformers that create nodes representing // come after all other transformers that create nodes representing
// objects that can belong to modules. // objects that can belong to modules.
&ModuleExpansionTransformer{ &ModuleExpansionTransformer{Concrete: b.ConcreteModule, Config: b.Config},
Concrete: b.ConcreteModule,
Config: b.Config,
},
// Connect so that the references are ready for targeting. We'll // Connect so that the references are ready for targeting. We'll
// have to connect again later for providers and so on. // have to connect again later for providers and so on.
@ -156,9 +144,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
&attachDataResourceDependenciesTransformer{}, &attachDataResourceDependenciesTransformer{},
// Target // Target
&TargetsTransformer{ &TargetsTransformer{Targets: b.Targets},
Targets: b.Targets,
},
// Detect when create_before_destroy must be forced on for a particular // Detect when create_before_destroy must be forced on for a particular
// node due to dependency edges, to avoid graph cycles during apply. // node due to dependency edges, to avoid graph cycles during apply.
@ -171,7 +157,6 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
// Close opened plugin connections // Close opened plugin connections
&CloseProviderTransformer{}, &CloseProviderTransformer{},
&CloseProvisionerTransformer{},
// Close the root module // Close the root module
&CloseRootModuleTransformer{}, &CloseRootModuleTransformer{},

View File

@ -25,9 +25,6 @@ type ConfigTransformer struct {
// Module is the module to add resources from. // Module is the module to add resources from.
Config *configs.Config Config *configs.Config
// Unique will only add resources that aren't already present in the graph.
Unique bool
// Mode will only add resources that match the given mode // Mode will only add resources that match the given mode
ModeFilter bool ModeFilter bool
Mode addrs.ResourceMode Mode addrs.ResourceMode