func resourcesFromConfig()

in scripts/check_importer_supports_engine/main.go [73:112]


func resourcesFromConfig(configPath string, unsupported map[string]bool) error {
	// Create tmpdir for outputting the configs
	tmp, err := ioutil.TempDir("", "")
	if err != nil {
		return fmt.Errorf("ioutil.TempDir = %v", err)
	}
	defer os.RemoveAll(tmp)

	// Generate configs from the top-level config
	if err := tfengine.Run(configPath, tmp, &tfengine.Options{Format: false, CacheDir: tmp}); err != nil {
		return fmt.Errorf("tfengine.Run(%q, %q) = %v", configPath, tmp, err)
	}

	// Run plan to verify configs.
	fs, err := ioutil.ReadDir(tmp)
	if err != nil {
		return fmt.Errorf("ioutil.ReadDir = %v", err)
	}

	for _, f := range fs {
		if !f.IsDir() {
			continue
		}
		dir := filepath.Join(tmp, f.Name())

		// Convert the configs not reference a GCS backend as the state bucket does not exist.
		if err := tfengine.ConvertToLocalBackend(dir); err != nil {
			return fmt.Errorf("ConvertToLocalBackend(%v): %v", dir, err)
		}
		init := exec.Command("terraform", "init")
		init.Dir = dir
		if b, err := init.CombinedOutput(); err != nil {
			return fmt.Errorf("command %v in %q: %v\n%v", init.Args, dir, err, string(b))
		}
		if err := addResources(dir, unsupported); err != nil {
			return fmt.Errorf("add resources from %q: %v", dir, err)
		}
	}
	return nil
}