From 30d6a403294a78a6381b27a6d092014088fe3e6c Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 29 May 2018 13:29:09 -0700 Subject: [PATCH] core: Give import graph access to schema, variables, outputs, locals During import we constrain provider configuration to allow only references to variables, but since provider configurations in child modules might refer to variables from the parent, we still need to include the module variables, outputs and locals in the graph here and attach the provider schemas. In future a better check would be that the provider configuration doesn't refer to anything that is currently unknown, but we'll save that for another day. --- terraform/context_import.go | 2 +- terraform/graph_builder_import.go | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/terraform/context_import.go b/terraform/context_import.go index 81bc7a98a6..71edfe2b19 100644 --- a/terraform/context_import.go +++ b/terraform/context_import.go @@ -60,7 +60,7 @@ func (c *Context) Import(opts *ImportOpts) (*State, tfdiags.Diagnostics) { builder := &ImportGraphBuilder{ ImportTargets: opts.Targets, Config: config, - Providers: c.components.ResourceProviders(), + Components: c.components, } // Build the graph! diff --git a/terraform/graph_builder_import.go b/terraform/graph_builder_import.go index e62c34f419..e7d6d20c78 100644 --- a/terraform/graph_builder_import.go +++ b/terraform/graph_builder_import.go @@ -17,8 +17,8 @@ type ImportGraphBuilder struct { // Module is a configuration to build the graph from. See ImportOpts.Config. Config *configs.Config - // Providers is the list of providers supported. - Providers []string + // Components is the factory for our available plugin components. + Components contextComponentFactory } // Build builds the graph according to the steps returned by Steps. @@ -54,11 +54,31 @@ func (b *ImportGraphBuilder) Steps() []GraphTransformer { // Add the import steps &ImportStateTransformer{Targets: b.ImportTargets}, - TransformProviders(b.Providers, concreteProvider, config), + // Add root variables + &RootVariableTransformer{Config: b.Config}, + + // Must be before TransformProviders and ReferenceTransformer, since + // schema is required to extract references from config. + &AttachSchemaTransformer{Components: b.Components}, + + TransformProviders(b.Components.ResourceProviders(), concreteProvider, config), // This validates that the providers only depend on variables &ImportProviderValidateTransformer{}, + // Add the local values + &LocalTransformer{Config: b.Config}, + + // Add the outputs + &OutputTransformer{Config: b.Config}, + + // Add module variables + &ModuleVariableTransformer{Config: b.Config}, + + // Connect so that the references are ready for targeting. We'll + // have to connect again later for providers and so on. + &ReferenceTransformer{}, + // Close opened plugin connections &CloseProviderTransformer{},