in internal/tfimport/tfimport.go [577:632]
func Run(rn runner.Runner, importRn runner.Runner, runArgs *RunArgs) error {
// Expand the config path (ex. expand ~).
inputDir, err := fileutil.Expand(runArgs.InputDir)
if err != nil {
return fmt.Errorf("expand path %q: %v", inputDir, err)
}
var successesTotal, failuresTotal []string
skipped := make(map[string]string)
var ie *importError
for {
failuresTotal = nil
successes, err := planAndImport(rn, importRn, runArgs, skipped)
successesTotal = append(successesTotal, successes...)
if err == nil {
// Either no successes, or no errors.
// No need to retry.
break
}
if !errors.As(err, &ie) {
// It's some other kind of error and we should return it.
return err
}
// It's an importError.
failuresTotal = ie.errMsgs
// If no successes, break out of the loop.
if len(successes) <= 0 {
break
}
// Some resources imported successfully, but others didn't.
// Time to retry.
log.Println("Some imports succeeded but others did not. Retrying the import, in case dependent values have now been populated.")
}
buf, err := template.WriteBuffer(summaryTmpl, map[string]interface{}{
"total": len(successesTotal) + len(skipped) + len(failuresTotal),
"successes": successesTotal,
"skipped": skipped,
"failures": failuresTotal,
})
if err != nil {
return fmt.Errorf("building summary template: %v", err)
}
log.Printf("%s\n", buf)
if ie != nil {
return ie
}
return nil
}