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:
parent
b5403059e6
commit
22fb82963c
|
@ -111,6 +111,10 @@ func (r *RawConfig) Copy() *RawConfig {
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
|
if r.Body != nil {
|
||||||
|
return NewRawConfigHCL2(r.Body)
|
||||||
|
}
|
||||||
|
|
||||||
newRaw := make(map[string]interface{})
|
newRaw := make(map[string]interface{})
|
||||||
for k, v := range r.Raw {
|
for k, v := range r.Raw {
|
||||||
newRaw[k] = v
|
newRaw[k] = v
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
hcl2 "github.com/hashicorp/hcl2/hcl"
|
||||||
"github.com/hashicorp/hil/ast"
|
"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) {
|
func TestRawConfigValue(t *testing.T) {
|
||||||
raw := map[string]interface{}{
|
raw := map[string]interface{}{
|
||||||
"foo": "${var.bar}",
|
"foo": "${var.bar}",
|
||||||
|
|
Loading…
Reference in New Issue