group the provider transformations

The series of provider transformations is important, and often repeated.
Group these together in a single transform function.
This commit is contained in:
James Bardin 2017-11-02 10:02:51 -04:00
parent 12a4a29cbd
commit 2f91007999
6 changed files with 38 additions and 58 deletions

View File

@ -87,19 +87,8 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
// Attach the state
&AttachStateTransformer{State: b.State},
// add configured providers
&ProviderConfigTransformer{
Module: b.Module,
Providers: b.Providers,
Concrete: concreteProvider,
},
// Create all the providers
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
&ProviderTransformer{},
&DisableProviderTransformer{},
&ParentProviderTransformer{},
&AttachProviderConfigTransformer{Module: b.Module},
// add providers
TransformProviders(b.Providers, concreteProvider, b.Module),
// Destruction ordering
&DestroyEdgeTransformer{Module: b.Module, State: b.State},

View File

@ -52,19 +52,7 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
// Add the import steps
&ImportStateTransformer{Targets: b.ImportTargets},
// add configured providers
&ProviderConfigTransformer{
Module: b.Module,
Providers: b.Providers,
Concrete: concreteProvider,
},
// Provider-related transformations
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
&ProviderTransformer{},
&DisableProviderTransformer{},
&ParentProviderTransformer{},
&AttachProviderConfigTransformer{Module: mod},
TransformProviders(b.Providers, concreteProvider, mod),
// This validates that the providers only depend on variables
&ImportProviderValidateTransformer{},

View File

@ -93,19 +93,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
// Add root variables
&RootVariableTransformer{Module: b.Module},
// add configured providers
&ProviderConfigTransformer{
Module: b.Module,
Providers: b.Providers,
Concrete: b.ConcreteProvider,
},
// Create all the providers
&MissingProviderTransformer{Providers: b.Providers, Concrete: b.ConcreteProvider},
&ProviderTransformer{},
&DisableProviderTransformer{},
&ParentProviderTransformer{},
&AttachProviderConfigTransformer{Module: b.Module},
TransformProviders(b.Providers, b.ConcreteProvider, b.Module),
// Provisioner-related transformations. Only add these if requested.
GraphTransformIf(

View File

@ -126,19 +126,7 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer {
// Add root variables
&RootVariableTransformer{Module: b.Module},
// add configured providers
&ProviderConfigTransformer{
Module: b.Module,
Providers: b.Providers,
Concrete: concreteProvider,
},
// Create all the providers
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
&ProviderTransformer{},
&DisableProviderTransformer{},
&ParentProviderTransformer{},
&AttachProviderConfigTransformer{Module: b.Module},
TransformProviders(b.Providers, concreteProvider, b.Module),
// Add the local values
&LocalTransformer{Module: b.Module},

View File

@ -127,12 +127,7 @@ func (t *DestroyEdgeTransformer) Transform(g *Graph) error {
&AttachResourceConfigTransformer{Module: t.Module},
&AttachStateTransformer{State: t.State},
// Add providers since they can affect destroy order as well
&MissingProviderTransformer{AllowAny: true, Concrete: providerFn},
&ProviderTransformer{},
&DisableProviderTransformer{},
&ParentProviderTransformer{},
&AttachProviderConfigTransformer{Module: t.Module},
TransformProviders(nil, providerFn, t.Module),
// Add all the variables. We can depend on resources through
// variables due to module parameters, and we need to properly

View File

@ -6,9 +6,41 @@ import (
"strings"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/dag"
)
func TransformProviders(providers []string, concrete ConcreteProviderNodeFunc, mod *module.Tree) GraphTransformer {
// If we have no providers, let the MissingProviderTransformer add anything required.
// This is used by the destroy edge transformer's internal dependency graph.
allowAny := providers == nil
return GraphTransformMulti(
// Add providers from the config
&ProviderConfigTransformer{
Module: mod,
Providers: providers,
Concrete: concrete,
},
// Add any remaining missing providers
&MissingProviderTransformer{
AllowAny: allowAny,
Providers: providers,
Concrete: concrete,
},
// Connect the providers
&ProviderTransformer{},
// Disable unused providers
&DisableProviderTransformer{},
// Connect provider to their parent provider nodes
&ParentProviderTransformer{},
// Attach configuration to each provider instance
&AttachProviderConfigTransformer{
Module: mod,
},
)
}
// GraphNodeProvider is an interface that nodes that can be a provider
// must implement.
// ProviderName returns the name of the provider this satisfies.