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:
parent
12a4a29cbd
commit
2f91007999
|
@ -87,19 +87,8 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Attach the state
|
// Attach the state
|
||||||
&AttachStateTransformer{State: b.State},
|
&AttachStateTransformer{State: b.State},
|
||||||
|
|
||||||
// add configured providers
|
// add providers
|
||||||
&ProviderConfigTransformer{
|
TransformProviders(b.Providers, concreteProvider, b.Module),
|
||||||
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},
|
|
||||||
|
|
||||||
// Destruction ordering
|
// Destruction ordering
|
||||||
&DestroyEdgeTransformer{Module: b.Module, State: b.State},
|
&DestroyEdgeTransformer{Module: b.Module, State: b.State},
|
||||||
|
|
|
@ -52,19 +52,7 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Add the import steps
|
// Add the import steps
|
||||||
&ImportStateTransformer{Targets: b.ImportTargets},
|
&ImportStateTransformer{Targets: b.ImportTargets},
|
||||||
|
|
||||||
// add configured providers
|
TransformProviders(b.Providers, concreteProvider, mod),
|
||||||
&ProviderConfigTransformer{
|
|
||||||
Module: b.Module,
|
|
||||||
Providers: b.Providers,
|
|
||||||
Concrete: concreteProvider,
|
|
||||||
},
|
|
||||||
|
|
||||||
// Provider-related transformations
|
|
||||||
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
|
|
||||||
&ProviderTransformer{},
|
|
||||||
&DisableProviderTransformer{},
|
|
||||||
&ParentProviderTransformer{},
|
|
||||||
&AttachProviderConfigTransformer{Module: mod},
|
|
||||||
|
|
||||||
// This validates that the providers only depend on variables
|
// This validates that the providers only depend on variables
|
||||||
&ImportProviderValidateTransformer{},
|
&ImportProviderValidateTransformer{},
|
||||||
|
|
|
@ -93,19 +93,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Add root variables
|
// Add root variables
|
||||||
&RootVariableTransformer{Module: b.Module},
|
&RootVariableTransformer{Module: b.Module},
|
||||||
|
|
||||||
// add configured providers
|
TransformProviders(b.Providers, b.ConcreteProvider, b.Module),
|
||||||
&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},
|
|
||||||
|
|
||||||
// Provisioner-related transformations. Only add these if requested.
|
// Provisioner-related transformations. Only add these if requested.
|
||||||
GraphTransformIf(
|
GraphTransformIf(
|
||||||
|
|
|
@ -126,19 +126,7 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Add root variables
|
// Add root variables
|
||||||
&RootVariableTransformer{Module: b.Module},
|
&RootVariableTransformer{Module: b.Module},
|
||||||
|
|
||||||
// add configured providers
|
TransformProviders(b.Providers, concreteProvider, b.Module),
|
||||||
&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 the local values
|
// Add the local values
|
||||||
&LocalTransformer{Module: b.Module},
|
&LocalTransformer{Module: b.Module},
|
||||||
|
|
|
@ -127,12 +127,7 @@ func (t *DestroyEdgeTransformer) Transform(g *Graph) error {
|
||||||
&AttachResourceConfigTransformer{Module: t.Module},
|
&AttachResourceConfigTransformer{Module: t.Module},
|
||||||
&AttachStateTransformer{State: t.State},
|
&AttachStateTransformer{State: t.State},
|
||||||
|
|
||||||
// Add providers since they can affect destroy order as well
|
TransformProviders(nil, providerFn, t.Module),
|
||||||
&MissingProviderTransformer{AllowAny: true, Concrete: providerFn},
|
|
||||||
&ProviderTransformer{},
|
|
||||||
&DisableProviderTransformer{},
|
|
||||||
&ParentProviderTransformer{},
|
|
||||||
&AttachProviderConfigTransformer{Module: t.Module},
|
|
||||||
|
|
||||||
// Add all the variables. We can depend on resources through
|
// Add all the variables. We can depend on resources through
|
||||||
// variables due to module parameters, and we need to properly
|
// variables due to module parameters, and we need to properly
|
||||||
|
|
|
@ -6,9 +6,41 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
|
"github.com/hashicorp/terraform/config/module"
|
||||||
"github.com/hashicorp/terraform/dag"
|
"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
|
// GraphNodeProvider is an interface that nodes that can be a provider
|
||||||
// must implement.
|
// must implement.
|
||||||
// ProviderName returns the name of the provider this satisfies.
|
// ProviderName returns the name of the provider this satisfies.
|
||||||
|
|
Loading…
Reference in New Issue