Merge pull request #29411 from hashicorp/jbardin/plan-nesting-single

handle null NestingSingle values
This commit is contained in:
James Bardin 2021-08-18 14:34:49 -04:00 committed by GitHub
commit 9f24b4dc68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
switch schema.Nesting {
case configschema.NestingSingle:
newAttrs := proposedNewAttributes(schema.Attributes, prior, config)
newV = cty.ObjectVal(newAttrs)
if !config.IsNull() {
newV = cty.ObjectVal(proposedNewAttributes(schema.Attributes, prior, config))
} else {
newV = cty.NullVal(config.Type())
}
case configschema.NestingList:
// Nested blocks are correlated by index.

View File

@ -1433,7 +1433,7 @@ func TestProposedNew(t *testing.T) {
}),
}),
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}))),
"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}))),
@ -1447,7 +1447,7 @@ func TestProposedNew(t *testing.T) {
}))),
}),
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}))),
"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}))),