2019-12-17 11:25:56 +01:00
|
|
|
package hcl2template
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
|
)
|
|
|
|
|
|
2020-02-06 11:49:21 +01:00
|
|
|
// Decodable structs are structs that can tell their hcl2 ObjectSpec; this
|
|
|
|
|
// config spec will be passed to hcldec.Decode and the result will be a
|
|
|
|
|
// cty.Value. This Value can then be applied on the said struct.
|
2019-12-17 11:25:56 +01:00
|
|
|
type Decodable interface {
|
|
|
|
|
ConfigSpec() hcldec.ObjectSpec
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 11:49:21 +01:00
|
|
|
func decodeHCL2Spec(body hcl.Body, ectx *hcl.EvalContext, dec Decodable) (cty.Value, hcl.Diagnostics) {
|
|
|
|
|
return hcldec.Decode(body, dec.ConfigSpec(), ectx)
|
2019-12-17 11:25:56 +01:00
|
|
|
}
|