handle null NestingSingle values

Null NestingSingle attributes were not being handled in ProposedNew
This commit is contained in:
James Bardin 2021-08-18 13:52:18 -04:00
parent c351f41e47
commit da007517b0
2 changed files with 7 additions and 4 deletions

View File

@ -311,8 +311,11 @@ func proposedNewNestedType(schema *configschema.Object, prior, config cty.Value)
var newV cty.Value var newV cty.Value
switch schema.Nesting { switch schema.Nesting {
case configschema.NestingSingle: case configschema.NestingSingle:
newAttrs := proposedNewAttributes(schema.Attributes, prior, config) if !config.IsNull() {
newV = cty.ObjectVal(newAttrs) newV = cty.ObjectVal(proposedNewAttributes(schema.Attributes, prior, config))
} else {
newV = cty.NullVal(config.Type())
}
case configschema.NestingList: case configschema.NestingList:
// Nested blocks are correlated by index. // Nested blocks are correlated by index.

View File

@ -1433,7 +1433,7 @@ func TestProposedNew(t *testing.T) {
}), }),
}), }),
cty.ObjectVal(map[string]cty.Value{ cty.ObjectVal(map[string]cty.Value{
"single": cty.ObjectVal(map[string]cty.Value{"bar": cty.NullVal(cty.String)}), "single": cty.NullVal(cty.Object(map[string]cty.Type{"bar": cty.String})),
"list": cty.NullVal(cty.List(cty.Object(map[string]cty.Type{"bar": cty.String}))), "list": cty.NullVal(cty.List(cty.Object(map[string]cty.Type{"bar": cty.String}))),
"map": cty.NullVal(cty.Map(cty.Object(map[string]cty.Type{"bar": cty.String}))), "map": cty.NullVal(cty.Map(cty.Object(map[string]cty.Type{"bar": cty.String}))),
"set": cty.NullVal(cty.Set(cty.Object(map[string]cty.Type{"bar": cty.String}))), "set": cty.NullVal(cty.Set(cty.Object(map[string]cty.Type{"bar": cty.String}))),
@ -1447,7 +1447,7 @@ func TestProposedNew(t *testing.T) {
}))), }))),
}), }),
cty.ObjectVal(map[string]cty.Value{ cty.ObjectVal(map[string]cty.Value{
"single": cty.ObjectVal(map[string]cty.Value{"bar": cty.NullVal(cty.String)}), "single": cty.NullVal(cty.Object(map[string]cty.Type{"bar": cty.String})),
"list": cty.NullVal(cty.List(cty.Object(map[string]cty.Type{"bar": cty.String}))), "list": cty.NullVal(cty.List(cty.Object(map[string]cty.Type{"bar": cty.String}))),
"map": cty.NullVal(cty.Map(cty.Object(map[string]cty.Type{"bar": cty.String}))), "map": cty.NullVal(cty.Map(cty.Object(map[string]cty.Type{"bar": cty.String}))),
"set": cty.NullVal(cty.Set(cty.Object(map[string]cty.Type{"bar": cty.String}))), "set": cty.NullVal(cty.Set(cty.Object(map[string]cty.Type{"bar": cty.String}))),