config: when copying a HCL2 RawConfig, don't corrupt it

Previously we were demoting HCL2 RawConfigs into empty old-school
RawConfigs on copy.
This commit is contained in:
Martin Atkins 2017-10-13 18:28:03 -07:00
parent b5403059e6
commit 22fb82963c
2 changed files with 17 additions and 0 deletions

View File

@ -111,6 +111,10 @@ func (r *RawConfig) Copy() *RawConfig {
r.lock.Lock()
defer r.lock.Unlock()
if r.Body != nil {
return NewRawConfigHCL2(r.Body)
}
newRaw := make(map[string]interface{})
for k, v := range r.Raw {
newRaw[k] = v

View File

@ -5,6 +5,7 @@ import (
"reflect"
"testing"
hcl2 "github.com/hashicorp/hcl2/hcl"
"github.com/hashicorp/hil/ast"
)
@ -435,6 +436,18 @@ func TestRawConfigCopy(t *testing.T) {
}
}
func TestRawConfigCopyHCL2(t *testing.T) {
rc := NewRawConfigHCL2(hcl2.EmptyBody())
rc2 := rc.Copy()
if rc.Body == nil {
t.Errorf("RawConfig copy has a nil Body")
}
if rc2.Raw != nil {
t.Errorf("RawConfig copy got a non-nil Raw")
}
}
func TestRawConfigValue(t *testing.T) {
raw := map[string]interface{}{
"foo": "${var.bar}",