Merge pull request #29928 from hashicorp/jbardin/ignore_null_map
`ignore_changes` converting null maps to empty maps, and applying marks.
This commit is contained in:
commit
33bcc715a0
|
@ -1289,14 +1289,19 @@ func processIgnoreChangesIndividual(prior, config cty.Value, ignoreChangesPath [
|
|||
}
|
||||
|
||||
var newVal cty.Value
|
||||
if len(configMap) == 0 {
|
||||
newVal = cty.MapValEmpty(v.Type().ElementType())
|
||||
} else {
|
||||
switch {
|
||||
case len(configMap) > 0:
|
||||
newVal = cty.MapVal(configMap)
|
||||
case v.IsNull():
|
||||
// if the config value was null, and no values remain in the map,
|
||||
// reset the value to null.
|
||||
newVal = v
|
||||
default:
|
||||
newVal = cty.MapValEmpty(v.Type().ElementType())
|
||||
}
|
||||
|
||||
if len(vMarks) > 0 {
|
||||
newVal = v.WithMarks(vMarks)
|
||||
newVal = newVal.WithMarks(vMarks)
|
||||
}
|
||||
|
||||
return newVal, nil
|
||||
|
|
|
@ -369,6 +369,54 @@ func TestProcessIgnoreChangesIndividual(t *testing.T) {
|
|||
"b": cty.StringVal("new b value"),
|
||||
}),
|
||||
},
|
||||
"null_map": {
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("ok"),
|
||||
"list": cty.ListVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"s": cty.StringVal("ok"),
|
||||
"map": cty.NullVal(cty.Map(cty.String)),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"a": cty.NullVal(cty.String),
|
||||
"list": cty.ListVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"s": cty.StringVal("ok"),
|
||||
"map": cty.NullVal(cty.Map(cty.String)),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
[]string{"a"},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"a": cty.StringVal("ok"),
|
||||
"list": cty.ListVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"s": cty.StringVal("ok"),
|
||||
"map": cty.NullVal(cty.Map(cty.String)),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
"marked_map": {
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"key": cty.StringVal("val"),
|
||||
}).Mark("marked"),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"key": cty.StringVal("new val"),
|
||||
}).Mark("marked"),
|
||||
}),
|
||||
[]string{`map["key"]`},
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"map": cty.MapVal(map[string]cty.Value{
|
||||
"key": cty.StringVal("val"),
|
||||
}).Mark("marked"),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
for name, test := range tests {
|
||||
|
|
Loading…
Reference in New Issue