From 00c812cfe8de18074784ea32ec8811accbcbc345 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Mon, 17 Feb 2020 15:53:05 +0100 Subject: [PATCH] insert "github.com/zclconf/go-cty/cty/json" encoding beforce hcl decoding things to make sure tests are working similarly as real life version --- hcl2template/internal/mock.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hcl2template/internal/mock.go b/hcl2template/internal/mock.go index 84d00d98a..0900c679a 100644 --- a/hcl2template/internal/mock.go +++ b/hcl2template/internal/mock.go @@ -6,9 +6,12 @@ import ( "context" "time" + "github.com/zclconf/go-cty/cty/json" + "github.com/hashicorp/hcl/v2/hcldec" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" + "github.com/zclconf/go-cty/cty" ) type NestedMockConfig struct { @@ -33,6 +36,21 @@ type MockConfig struct { } func (b *MockConfig) Prepare(raws ...interface{}) error { + for i, raw := range raws { + cval, ok := raw.(cty.Value) + if !ok { + continue + } + b, err := json.Marshal(cval, cty.DynamicPseudoType) + if err != nil { + return err + } + ccval, err := json.Unmarshal(b, cty.DynamicPseudoType) + if err != nil { + return err + } + raws[i] = ccval + } return config.Decode(b, &config.DecodeOpts{ Interpolate: true, }, raws...)