From 340686a383cffd5bb04274b7c81f27c60d4cba81 Mon Sep 17 00:00:00 2001 From: Patrick Van Stee Date: Thu, 7 May 2020 21:50:32 -0400 Subject: [PATCH] Support parsing json config with hcl v2 Signed-off-by: Patrick Van Stee --- bake/hcl.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bake/hcl.go b/bake/hcl.go index cce83821..7dd372a9 100644 --- a/bake/hcl.go +++ b/bake/hcl.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/hcl/v2/ext/userfunc" "github.com/hashicorp/hcl/v2/hclsimple" "github.com/hashicorp/hcl/v2/hclsyntax" + "github.com/hashicorp/hcl/v2/json" "github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty/function" "github.com/zclconf/go-cty/cty/function/stdlib" @@ -73,8 +74,16 @@ type staticConfig struct { } func ParseHCL(dt []byte, fn string) (*Config, error) { + var file *hcl.File + var diags hcl.Diagnostics + // Decode user defined functions. - file, diags := hclsyntax.ParseConfig(dt, fn, hcl.Pos{Line: 1, Column: 1}) + fnl := strings.ToLower(fn) + if strings.HasSuffix(fnl, ".json") { + file, diags = json.Parse(dt, fn) + } else { + file, diags = hclsyntax.ParseConfig(dt, fn, hcl.Pos{Line: 1, Column: 1}) + } if diags.HasErrors() { return nil, diags }