func LoadMPTFHclBlocks()

in pkg/mptf_config.go [134:178]


func LoadMPTFHclBlocks(ignoreUnsupportedBlock bool, dir string) ([]*golden.HclBlock, error) {
	fs := filesystem.Fs
	matches, err := afero.Glob(fs, filepath.Join(dir, "*.mptf.hcl"))
	if err != nil {
		return nil, err
	}
	if len(matches) == 0 {
		return nil, fmt.Errorf("no `.mptf.hcl` file found at %s", dir)
	}

	var blocks []*golden.HclBlock

	for _, filename := range matches {
		content, fsErr := afero.ReadFile(fs, filename)
		if fsErr != nil {
			err = multierror.Append(err, fsErr)
			continue
		}
		readFile, diag := hclsyntax.ParseConfig(content, filename, hcl.InitialPos)
		if diag.HasErrors() {
			err = multierror.Append(err, diag.Errs()...)
			continue
		}
		writeFile, _ := hclwrite.ParseConfig(content, filename, hcl.InitialPos)
		readBlocks := readFile.Body.(*hclsyntax.Body).Blocks

		writeBlocks := writeFile.Body().Blocks()
		blocks = append(blocks, golden.AsHclBlocks(readBlocks, writeBlocks)...)
	}
	if err != nil {
		return nil, err
	}

	var r []*golden.HclBlock
	for _, b := range blocks {
		if golden.IsBlockTypeWanted(b.Type) {
			r = append(r, b)
			continue
		}
		if !ignoreUnsupportedBlock {
			err = multierror.Append(err, fmt.Errorf("invalid block type: %s %s", b.Type, b.Range().String()))
		}
	}
	return r, err
}