mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-21 23:41:41 -04:00
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
22 lines
638 B
Go
22 lines
638 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package hcl2template
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl/v2"
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
// 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.
|
|
type Decodable interface {
|
|
ConfigSpec() hcldec.ObjectSpec
|
|
}
|
|
|
|
func decodeHCL2Spec(body hcl.Body, ectx *hcl.EvalContext, dec Decodable) (cty.Value, hcl.Diagnostics) {
|
|
return hcldec.Decode(body, dec.ConfigSpec(), ectx)
|
|
}
|