X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=vendor%2Fgithub.com%2Fhashicorp%2Fterraform%2Fterraform%2Fcontext_import.go;h=313e9094f96da2bd426dedcb9dc9b9bbc0973917;hb=03f98475e953bf27db3019fa0840ebc6df7fd295;hp=f1d57760df3e6953d9f3d45c09492c244949893a;hpb=21252084ae8c5f3321b45008fd5a6b162b293407;p=github%2Ffretlink%2Fterraform-provider-statuscake.git diff --git a/vendor/github.com/hashicorp/terraform/terraform/context_import.go b/vendor/github.com/hashicorp/terraform/terraform/context_import.go index f1d5776..313e909 100644 --- a/vendor/github.com/hashicorp/terraform/terraform/context_import.go +++ b/vendor/github.com/hashicorp/terraform/terraform/context_import.go @@ -1,7 +1,10 @@ package terraform import ( - "github.com/hashicorp/terraform/config/module" + "github.com/hashicorp/terraform/addrs" + "github.com/hashicorp/terraform/configs" + "github.com/hashicorp/terraform/states" + "github.com/hashicorp/terraform/tfdiags" ) // ImportOpts are used as the configuration for Import. @@ -9,23 +12,23 @@ type ImportOpts struct { // Targets are the targets to import Targets []*ImportTarget - // Module is optional, and specifies a config module that is loaded - // into the graph and evaluated. The use case for this is to provide - // provider configuration. - Module *module.Tree + // Config is optional, and specifies a config tree that will be loaded + // into the graph and evaluated. This is the source for provider + // configurations. + Config *configs.Config } // ImportTarget is a single resource to import. type ImportTarget struct { - // Addr is the full resource address of the resource to import. - // Example: "module.foo.aws_instance.bar" - Addr string + // Addr is the address for the resource instance that the new object should + // be imported into. + Addr addrs.AbsResourceInstance // ID is the ID of the resource to import. This is resource-specific. ID string - // Provider string - Provider string + // ProviderAddr is the address of the provider that should handle the import. + ProviderAddr addrs.AbsProviderConfig } // Import takes already-created external resources and brings them @@ -38,7 +41,9 @@ type ImportTarget struct { // Further, this operation also gracefully handles partial state. If during // an import there is a failure, all previously imported resources remain // imported. -func (c *Context) Import(opts *ImportOpts) (*State, error) { +func (c *Context) Import(opts *ImportOpts) (*states.State, tfdiags.Diagnostics) { + var diags tfdiags.Diagnostics + // Hold a lock since we can modify our own state here defer c.acquireRun("import")() @@ -47,31 +52,32 @@ func (c *Context) Import(opts *ImportOpts) (*State, error) { // If no module is given, default to the module configured with // the Context. - module := opts.Module - if module == nil { - module = c.module + config := opts.Config + if config == nil { + config = c.config } // Initialize our graph builder builder := &ImportGraphBuilder{ ImportTargets: opts.Targets, - Module: module, - Providers: c.components.ResourceProviders(), + Config: config, + Components: c.components, + Schemas: c.schemas, } // Build the graph! - graph, err := builder.Build(RootModulePath) - if err != nil { - return c.state, err + graph, graphDiags := builder.Build(addrs.RootModuleInstance) + diags = diags.Append(graphDiags) + if graphDiags.HasErrors() { + return c.state, diags } // Walk it - if _, err := c.walk(graph, nil, walkImport); err != nil { - return c.state, err + _, walkDiags := c.walk(graph, walkImport) + diags = diags.Append(walkDiags) + if walkDiags.HasErrors() { + return c.state, diags } - // Clean the state - c.state.prune() - - return c.state, nil + return c.state, diags }