github.com/hashicorp/packer@v1.14.3/hcl2template/decode.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package hcl2template
     5  
     6  import (
     7  	"github.com/hashicorp/hcl/v2"
     8  	"github.com/hashicorp/hcl/v2/hcldec"
     9  	"github.com/zclconf/go-cty/cty"
    10  )
    11  
    12  // Decodable structs are structs that can tell their hcl2 ObjectSpec; this
    13  // config spec will be passed to hcldec.Decode and the result will be a
    14  // cty.Value. This Value can then be applied on the said struct.
    15  type Decodable interface {
    16  	ConfigSpec() hcldec.ObjectSpec
    17  }
    18  
    19  func decodeHCL2Spec(body hcl.Body, ectx *hcl.EvalContext, dec Decodable) (cty.Value, hcl.Diagnostics) {
    20  	return hcldec.Decode(body, dec.ConfigSpec(), ectx)
    21  }