MCPcopy
hub / github.com/Azure/aztfexport / BatchImport

Function BatchImport

internal/run.go:19–148  ·  view source on GitHub ↗
(ctx context.Context, cfg config.NonInteractiveModeConfig)

Source from the content-addressed store, hash-verified

17)
18
19func BatchImport(ctx context.Context, cfg config.NonInteractiveModeConfig) error {
20 var c meta.Meta = internalmeta.NewGroupMetaDummy(cfg.ResourceGroupName, cfg.ProviderName)
21 if !cfg.MockMeta {
22 var err error
23 c, err = meta.NewMeta(cfg.Config)
24 if err != nil {
25 return err
26 }
27 }
28
29 var errors []string
30
31 f := func(msg Messager) error {
32 msg.SetStatus("Initializing...")
33 if err := c.Init(ctx); err != nil {
34 return err
35 }
36
37 defer func() {
38 msg.SetStatus("DeInitializing...")
39 // #nosec G104
40 c.DeInit(ctx)
41 }()
42
43 msg.SetStatus("Listing resources...")
44 list, err := c.ListResource(ctx)
45 if err != nil {
46 return err
47 }
48
49 msg.SetStatus("Exporting Skipped Resource file...")
50 if err := c.WriteSkippedResources(ctx, list); err != nil {
51 return fmt.Errorf("exporting Skipped Resource file: %v", err)
52 }
53
54 msg.SetStatus("Exporting Resource Mapping file...")
55 if err := c.WriteResourceMapping(ctx, list); err != nil {
56 return fmt.Errorf("exporting Resource Mapping file: %v", err)
57 }
58
59 if len(list.NonSkipped()) == 0 {
60 return fmt.Errorf("no resource found")
61 }
62
63 // Return early if only generating mapping file
64 if cfg.GenMappingFileOnly {
65 return nil
66 }
67
68 for i := 0; i < len(list); i += cfg.Parallelism {
69 n := cfg.Parallelism
70 if i+cfg.Parallelism > len(list) {
71 n = len(list) - i
72 }
73
74 var importList []*meta.ImportItem
75 messages := []string{"Importing resources..."}
76

Callers 8

realMainFunction · 0.92
runCaseFunction · 0.92
runCaseFunction · 0.92
TestQueryModeFunction · 0.92
runCaseFunction · 0.92
TestAppendModeFunction · 0.92
TestAppendToModuleFunction · 0.92
runHCLOnlyFunction · 0.92

Calls 14

ListResourceMethod · 0.95
NewMetaFunction · 0.92
NewStdoutMessagerFunction · 0.85
NonSkippedMethod · 0.80
SkipMethod · 0.80
SetStatusMethod · 0.65
InitMethod · 0.65
DeInitMethod · 0.65
WriteSkippedResourcesMethod · 0.65
WriteResourceMappingMethod · 0.65
ParallelImportMethod · 0.65
PushStateMethod · 0.65

Tested by 7

runCaseFunction · 0.74
runCaseFunction · 0.74
TestQueryModeFunction · 0.74
runCaseFunction · 0.74
TestAppendModeFunction · 0.74
TestAppendToModuleFunction · 0.74
runHCLOnlyFunction · 0.74