diff --git a/terraform/graph_builder_apply.go b/terraform/graph_builder_apply.go index 1a0c4a9cb..ff59edc8e 100644 --- a/terraform/graph_builder_apply.go +++ b/terraform/graph_builder_apply.go @@ -119,13 +119,18 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer { // Add module variables &ModuleVariableTransformer{Config: b.Config}, - // Must be before TransformProviders and ReferenceTransformer, since - // schema is required to extract references from config. + // Must be run before TransformProviders so that resource configurations + // can be analyzed. &AttachSchemaTransformer{Schemas: b.Schemas}, // add providers 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 &RemovedModuleTransformer{Config: b.Config, State: b.State}, diff --git a/terraform/graph_builder_eval.go b/terraform/graph_builder_eval.go index 0da15b3b9..6ceb2264d 100644 --- a/terraform/graph_builder_eval.go +++ b/terraform/graph_builder_eval.go @@ -73,12 +73,6 @@ func (b *EvalGraphBuilder) Steps() []GraphTransformer { // Add root variables &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 &LocalTransformer{Config: b.Config}, @@ -88,6 +82,17 @@ func (b *EvalGraphBuilder) Steps() []GraphTransformer { // Add module variables &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 // have to connect again later for providers and so on. &ReferenceTransformer{}, diff --git a/terraform/graph_builder_import.go b/terraform/graph_builder_import.go index 50f38e394..036ae3259 100644 --- a/terraform/graph_builder_import.go +++ b/terraform/graph_builder_import.go @@ -61,12 +61,17 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer { // Add root variables &RootVariableTransformer{Config: b.Config}, - // Must be before TransformProviders and ReferenceTransformer, since - // schema is required to extract references from config. + // Must be run before TransformProviders so that resource configurations + // can be analyzed. &AttachSchemaTransformer{Schemas: b.Schemas}, 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 &ImportProviderValidateTransformer{}, diff --git a/terraform/graph_builder_plan.go b/terraform/graph_builder_plan.go index ed734d704..3142c0a56 100644 --- a/terraform/graph_builder_plan.go +++ b/terraform/graph_builder_plan.go @@ -107,6 +107,8 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer { &MissingProvisionerTransformer{Provisioners: b.Components.ResourceProvisioners()}, + // Must be run before TransformProviders so that resource configurations + // can be analyzed. &AttachSchemaTransformer{Schemas: b.Schemas}, // Add module variables @@ -116,13 +118,14 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer { 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 &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 // have to connect again later for providers and so on. &ReferenceTransformer{}, diff --git a/terraform/graph_builder_refresh.go b/terraform/graph_builder_refresh.go index 87892191c..8e4dfb625 100644 --- a/terraform/graph_builder_refresh.go +++ b/terraform/graph_builder_refresh.go @@ -138,12 +138,17 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer { // Add module variables &ModuleVariableTransformer{Config: b.Config}, - // Must be before TransformProviders and ReferenceTransformer, since - // schema is required to extract references from 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 // have to connect again later for providers and so on. &ReferenceTransformer{}, diff --git a/terraform/transform_destroy_edge.go b/terraform/transform_destroy_edge.go index fdbf5081a..80adf666a 100644 --- a/terraform/transform_destroy_edge.go +++ b/terraform/transform_destroy_edge.go @@ -139,12 +139,17 @@ func (t *DestroyEdgeTransformer) Transform(g *Graph) error { &RootVariableTransformer{Config: t.Config}, &ModuleVariableTransformer{Config: t.Config}, - // Must be before ReferenceTransformer, since schema is required to - // extract references from config. + // Must be run before TransformProviders so that resource configurations + // can be analyzed. &AttachSchemaTransformer{Schemas: t.Schemas}, 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{}, }