core: Run AttachSchemaTransformer twice to catch provider nodes too

Both ProviderTransformer and ReferenceTransformer need schema information,
and so there's a chicken-and-egg problem here where previously the schemas
were not getting attached to provider nodes created during
ProviderTransformer.

As a stop-gap measure for now we'll just run AttachSchemaTransformer
twice, so we can catch any new nodes created during the provider
transforms.
This commit is contained in:
Martin Atkins 2018-05-31 13:00:17 -07:00
parent 88b5607a7a
commit f7aa06726a
6 changed files with 46 additions and 18 deletions

View File

@ -119,13 +119,18 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
// Add module variables // Add module variables
&ModuleVariableTransformer{Config: b.Config}, &ModuleVariableTransformer{Config: b.Config},
// Must be before TransformProviders and ReferenceTransformer, since // Must be run before TransformProviders so that resource configurations
// schema is required to extract references from config. // can be analyzed.
&AttachSchemaTransformer{Schemas: b.Schemas}, &AttachSchemaTransformer{Schemas: b.Schemas},
// add providers // add providers
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config), TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
// Attach schema to the newly-created provider nodes.
// (Will also redundantly re-attach schema to existing resource nodes,
// but that's okay.)
&AttachSchemaTransformer{Schemas: b.Schemas},
// Remove modules no longer present in the config // Remove modules no longer present in the config
&RemovedModuleTransformer{Config: b.Config, State: b.State}, &RemovedModuleTransformer{Config: b.Config, State: b.State},

View File

@ -73,12 +73,6 @@ func (b *EvalGraphBuilder) Steps() []GraphTransformer {
// Add root variables // Add root variables
&RootVariableTransformer{Config: b.Config}, &RootVariableTransformer{Config: b.Config},
// Must be before TransformProviders and ReferenceTransformer, since
// schema is required to extract references from config.
&AttachSchemaTransformer{Schemas: b.Schemas},
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
// Add the local values // Add the local values
&LocalTransformer{Config: b.Config}, &LocalTransformer{Config: b.Config},
@ -88,6 +82,17 @@ func (b *EvalGraphBuilder) Steps() []GraphTransformer {
// Add module variables // Add module variables
&ModuleVariableTransformer{Config: b.Config}, &ModuleVariableTransformer{Config: b.Config},
// Must be run before TransformProviders so that resource configurations
// can be analyzed.
&AttachSchemaTransformer{Schemas: b.Schemas},
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
// Attach schema to the newly-created provider nodes.
// (Will also redundantly re-attach schema to existing resource nodes,
// but that's okay.)
&AttachSchemaTransformer{Schemas: b.Schemas},
// 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.
&ReferenceTransformer{}, &ReferenceTransformer{},

View File

@ -61,12 +61,17 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer {
// Add root variables // Add root variables
&RootVariableTransformer{Config: b.Config}, &RootVariableTransformer{Config: b.Config},
// Must be before TransformProviders and ReferenceTransformer, since // Must be run before TransformProviders so that resource configurations
// schema is required to extract references from config. // can be analyzed.
&AttachSchemaTransformer{Schemas: b.Schemas}, &AttachSchemaTransformer{Schemas: b.Schemas},
TransformProviders(b.Components.ResourceProviders(), concreteProvider, config), TransformProviders(b.Components.ResourceProviders(), concreteProvider, config),
// Attach schema to the newly-created provider nodes.
// (Will also redundantly re-attach schema to existing resource nodes,
// but that's okay.)
&AttachSchemaTransformer{Schemas: b.Schemas},
// This validates that the providers only depend on variables // This validates that the providers only depend on variables
&ImportProviderValidateTransformer{}, &ImportProviderValidateTransformer{},

View File

@ -107,6 +107,8 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
&MissingProvisionerTransformer{Provisioners: b.Components.ResourceProvisioners()}, &MissingProvisionerTransformer{Provisioners: b.Components.ResourceProvisioners()},
// Must be run before TransformProviders so that resource configurations
// can be analyzed.
&AttachSchemaTransformer{Schemas: b.Schemas}, &AttachSchemaTransformer{Schemas: b.Schemas},
// Add module variables // Add module variables
@ -116,13 +118,14 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
TransformProviders(b.Components.ResourceProviders(), b.ConcreteProvider, b.Config), TransformProviders(b.Components.ResourceProviders(), b.ConcreteProvider, b.Config),
// Attach schema to the newly-created provider nodes.
// (Will also redundantly re-attach schema to existing resource nodes,
// but that's okay.)
&AttachSchemaTransformer{Schemas: b.Schemas},
// Remove modules no longer present in the config // Remove modules no longer present in the config
&RemovedModuleTransformer{Config: b.Config, State: b.State}, &RemovedModuleTransformer{Config: b.Config, State: b.State},
// Must be before ReferenceTransformer, since schema is required to
// extract references from config.
&AttachSchemaTransformer{Schemas: b.Schemas},
// 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.
&ReferenceTransformer{}, &ReferenceTransformer{},

View File

@ -138,12 +138,17 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer {
// Add module variables // Add module variables
&ModuleVariableTransformer{Config: b.Config}, &ModuleVariableTransformer{Config: b.Config},
// Must be before TransformProviders and ReferenceTransformer, since // Must be run before TransformProviders so that resource configurations
// schema is required to extract references from config. // can be analyzed.
&AttachSchemaTransformer{Schemas: b.Schemas}, &AttachSchemaTransformer{Schemas: b.Schemas},
TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config), TransformProviders(b.Components.ResourceProviders(), concreteProvider, b.Config),
// Attach schema to the newly-created provider nodes.
// (Will also redundantly re-attach schema to existing resource nodes,
// but that's okay.)
&AttachSchemaTransformer{Schemas: b.Schemas},
// 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.
&ReferenceTransformer{}, &ReferenceTransformer{},

View File

@ -139,12 +139,17 @@ func (t *DestroyEdgeTransformer) Transform(g *Graph) error {
&RootVariableTransformer{Config: t.Config}, &RootVariableTransformer{Config: t.Config},
&ModuleVariableTransformer{Config: t.Config}, &ModuleVariableTransformer{Config: t.Config},
// Must be before ReferenceTransformer, since schema is required to // Must be run before TransformProviders so that resource configurations
// extract references from config. // can be analyzed.
&AttachSchemaTransformer{Schemas: t.Schemas}, &AttachSchemaTransformer{Schemas: t.Schemas},
TransformProviders(nil, providerFn, t.Config), TransformProviders(nil, providerFn, t.Config),
// Attach schema to the newly-created provider nodes.
// (Will also redundantly re-attach schema to existing resource nodes,
// but that's okay.)
&AttachSchemaTransformer{Schemas: t.Schemas},
&ReferenceTransformer{}, &ReferenceTransformer{},
} }