don't retain removed map values
Make sure values removed from a map during apply are not copied into the new map. The broken test is no longer valid in this case, and the updated diff.Apply should prevent the case it used to cover.
This commit is contained in:
parent
0f883b118a
commit
0696cf7245
|
@ -1110,7 +1110,6 @@ func stripSchema(s *schema.Schema) *schema.Schema {
|
|||
// very uncommon nor was it reliable before 0.12 either.
|
||||
func normalizeNullValues(dst, src cty.Value, preferDst bool) cty.Value {
|
||||
ty := dst.Type()
|
||||
|
||||
if !src.IsNull() && !src.IsKnown() {
|
||||
// While this seems backwards to return src when preferDst is set, it
|
||||
// means this might be a plan scenario, and it must retain unknown
|
||||
|
@ -1154,7 +1153,12 @@ func normalizeNullValues(dst, src cty.Value, preferDst bool) cty.Value {
|
|||
|
||||
srcMap := src.AsValueMap()
|
||||
for key, v := range srcMap {
|
||||
dstVal := dstMap[key]
|
||||
dstVal, ok := dstMap[key]
|
||||
if !ok && !preferDst && ty.IsMapType() {
|
||||
// don't transfer old map values to dst during apply
|
||||
continue
|
||||
}
|
||||
|
||||
if dstVal == cty.NilVal {
|
||||
if preferDst && ty.IsMapType() {
|
||||
// let plan shape this map however it wants
|
||||
|
|
|
@ -795,26 +795,6 @@ func TestNormalizeNullValues(t *testing.T) {
|
|||
}))),
|
||||
}),
|
||||
},
|
||||
{
|
||||
// Retain the zero value within the map
|
||||
Src: cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("a"),
|
||||
"b": cty.StringVal(""),
|
||||
}),
|
||||
}),
|
||||
Dst: cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("a"),
|
||||
}),
|
||||
}),
|
||||
Expect: cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("a"),
|
||||
"b": cty.StringVal(""),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
{
|
||||
// Retain don't re-add unexpected planned values in a map
|
||||
Src: cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -835,6 +815,26 @@ func TestNormalizeNullValues(t *testing.T) {
|
|||
}),
|
||||
Plan: true,
|
||||
},
|
||||
{
|
||||
// Remove extra values after apply
|
||||
Src: cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("a"),
|
||||
"b": cty.StringVal("b"),
|
||||
}),
|
||||
}),
|
||||
Dst: cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("a"),
|
||||
}),
|
||||
}),
|
||||
Expect: cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("a"),
|
||||
}),
|
||||
}),
|
||||
Plan: false,
|
||||
},
|
||||
{
|
||||
Src: cty.ObjectVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("a"),
|
||||
|
|
Loading…
Reference in New Issue