From f7aa06726a9c99bfa02cd42d4bd147fefe33aad4 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 31 May 2018 13:00:17 -0700 Subject: [PATCH] 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. --- terraform/graph_builder_apply.go | 9 +++++++-- terraform/graph_builder_eval.go | 17 +++++++++++------ terraform/graph_builder_import.go | 9 +++++++-- terraform/graph_builder_plan.go | 11 +++++++---- terraform/graph_builder_refresh.go | 9 +++++++-- terraform/transform_destroy_edge.go | 9 +++++++-- 6 files changed, 46 insertions(+), 18 deletions(-) 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{}, }