@@ -5,66 +5,11 @@ import (
55 "log"
66
77 "github.com/hashicorp/terraform/internal/addrs"
8- "github.com/hashicorp/terraform/internal/configs"
98 "github.com/hashicorp/terraform/internal/providers"
109 "github.com/hashicorp/terraform/internal/states"
1110 "github.com/hashicorp/terraform/internal/tfdiags"
1211)
1312
14- // ImportStateTransformer is a GraphTransformer that adds nodes to the
15- // graph to represent the imports we want to do for resources.
16- type ImportStateTransformer struct {
17- Targets []* ImportTarget
18- Config * configs.Config
19- skip bool
20- }
21-
22- func (t * ImportStateTransformer ) Transform (g * Graph ) error {
23- if t .skip {
24- return nil
25- }
26-
27- for _ , target := range t .Targets {
28- // This is only likely to happen in misconfigured tests
29- if t .Config == nil {
30- return fmt .Errorf ("cannot import into an empty configuration" )
31- }
32-
33- // Get the module config
34- modCfg := t .Config .Descendent (target .Addr .Module .Module ())
35- if modCfg == nil {
36- return fmt .Errorf ("module %s not found" , target .Addr .Module .Module ())
37- }
38-
39- providerAddr := addrs.AbsProviderConfig {
40- Module : target .Addr .Module .Module (),
41- }
42-
43- // Try to find the resource config
44- rsCfg := modCfg .Module .ResourceByAddr (target .Addr .Resource .Resource )
45- if rsCfg != nil {
46- // Get the provider FQN for the resource from the resource configuration
47- providerAddr .Provider = rsCfg .Provider
48-
49- // Get the alias from the resource's provider local config
50- providerAddr .Alias = rsCfg .ProviderConfigAddr ().Alias
51- } else {
52- // Resource has no matching config, so use an implied provider
53- // based on the resource type
54- rsProviderType := target .Addr .Resource .Resource .ImpliedProvider ()
55- providerAddr .Provider = modCfg .Module .ImpliedProviderForUnqualifiedType (rsProviderType )
56- }
57-
58- node := & graphNodeImportState {
59- Addr : target .Addr ,
60- ID : target .ID ,
61- ProviderAddr : providerAddr ,
62- }
63- g .Add (node )
64- }
65- return nil
66- }
67-
6813type graphNodeImportState struct {
6914 Addr addrs.AbsResourceInstance // Addr is the resource address to import into
7015 ID string // ID is the ID to import as
0 commit comments