func IsEmptyDir(path string) (bool, error) {
	if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
		return true, nil
	}
	p := NewParser(nil)
	fs, os, diags := p.dirFiles(path)
	if diags.HasErrors() {
		return false, diags
	}
	return len(fs) == 0 && len(os) == 0, nil
}
IsEmptyDir returns true if the given filesystem path contains no Terraform
configuration files.

Unlike the methods of the Parser type, this function always consults the
real filesystem, and thus it isn't appropriate to use when working with
configuration loaded from a plan file.
package configs
import (
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"github.com/hashicorp/hcl/v2"
)
func (p *Parser) LoadConfigDir(path string) (*Module, hcl.Diagnostics) {
	primaryPaths, overridePaths, diags := p.dirFiles(path)
	if diags.HasErrors() {
		return nil, diags
	}
	primary, fDiags := p.loadFiles(primaryPaths, false)
	diags = append(diags, fDiags...)
	override, fDiags := p.loadFiles(overridePaths, true)
	diags = append(diags, fDiags...)
	mod, modDiags := NewModule(primary, override)
	diags = append(diags, modDiags...)
	mod.SourceDir = path
	return mod, diags
}
func (p Parser) ConfigDirFiles(dir string) (primary, override []string, diags hcl.Diagnostics) {
	return p.dirFiles(dir)
}
func (p *Parser) IsConfigDir(path string) bool {
	primaryPaths, overridePaths, _ := p.dirFiles(path)
	return (len(primaryPaths) + len(overridePaths)) > 0
}
func (p *Parser) loadFiles(paths []string, override bool) ([]*File, hcl.Diagnostics) {
	var files []*File
	var diags hcl.Diagnostics
	for _, path := range paths {
		var f *File
		var fDiags hcl.Diagnostics
		if override {
			f, fDiags = p.LoadConfigFileOverride(path)
		} else {
			f, fDiags = p.LoadConfigFile(path)
		}
		diags = append(diags, fDiags...)
		if f != nil {
			files = append(files, f)
		}
	}
	return files, diags
}
func (p *Parser) dirFiles(dir string) (primary, override []string, diags hcl.Diagnostics) {
	infos, err := p.fs.ReadDir(dir)
	if err != nil {
		diags = append(diags, &hcl.Diagnostic{
			Severity: hcl.DiagError,
			Summary:  "Failed to read module directory",
			Detail:   fmt.Sprintf("Module directory %s does not exist or cannot be read.", dir),
		})
		return
	}
	for _, info := range infos {
		if info.IsDir() {
			continue
		}
		name := info.Name()
		ext := fileExt(name)
		if ext == "" || IsIgnoredFile(name) {
			continue
		}
		baseName := name[:len(name)-len(ext)]  
		isOverride := baseName == "override" || strings.HasSuffix(baseName, "_override")
		fullPath := filepath.Join(dir, name)
		if isOverride {
			override = append(override, fullPath)
		} else {
			primary = append(primary, fullPath)
		}
	}
	return
}
func fileExt(path string) string {
	if strings.HasSuffix(path, ".tf") {
		return ".tf"
	} else if strings.HasSuffix(path, ".tf.json") {
		return ".tf.json"
	} else {
		return ""
	}
}
func IsIgnoredFile(name string) bool {
	return strings.HasPrefix(name, ".") ||  
		strings.HasSuffix(name, "~") ||  
		strings.HasPrefix(name, "#") && strings.HasSuffix(name, "#")  
}