func CtyValueToMap(value *cty.Value) (map[string]interface{}, error) {
	b, err := ctyjson.Marshal(*value, cty.DynamicPseudoType)
	if err != nil {
		return nil, err
	}
	var jr struct {
		Value map[string]interface{}
	}
	if err := json.Unmarshal(b, &jr); err != nil {
		return nil, err
	}
	return jr.Value, nil
}
CtyValueToMap converts a cty.Value to a map.
HCL decoder can't unmarshal into map[string]interface{}, so make it unmarshal to a cty.Value and manually convert to map.
package hcl
import (
	"encoding/json"
	"fmt"
	"os/exec"
	"github.com/GoogleCloudPlatform/healthcare-data-protection-suite/internal/runner"
	"github.com/hashicorp/hcl/v2/hclsimple"
	"github.com/zclconf/go-cty/cty"
	ctyjson "github.com/zclconf/go-cty/cty/json"
)
func FormatDir(rn runner.Runner, dir string) error {
	tfFmt := exec.Command("terraform", "fmt", "-recursive")
	tfFmt.Dir = dir
	if _, err := rn.CmdOutput(tfFmt); err != nil {
		return fmt.Errorf("format terraform files: %v", err)
	}
	return nil
}
func ToJSON(b []byte) ([]byte, error) {
	var wrap struct {
		Value *cty.Value `hcl:"value"`
	}
	b = []byte(fmt.Sprintf("value = {\n%v\n}", string(b)))
	if err := hclsimple.Decode("file.hcl", []byte(b), nil, &wrap); err != nil {
		return nil, fmt.Errorf("convert HCL to JSON: %v", err)
	}
	m, err := CtyValueToMap(wrap.Value)
	if err != nil {
		return nil, err
	}
	return json.Marshal(m)
}