From da007517b0e2cf164374e77407f13dc69c8e294b Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 18 Aug 2021 13:52:18 -0400 Subject: [PATCH] handle null NestingSingle values Null NestingSingle attributes were not being handled in ProposedNew --- internal/plans/objchange/objchange.go | 7 +++++-- internal/plans/objchange/objchange_test.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/plans/objchange/objchange.go b/internal/plans/objchange/objchange.go index 51dd2b98b..281b9dd13 100644 --- a/internal/plans/objchange/objchange.go +++ b/internal/plans/objchange/objchange.go @@ -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. diff --git a/internal/plans/objchange/objchange_test.go b/internal/plans/objchange/objchange_test.go index 8221f99bd..7facea9e5 100644 --- a/internal/plans/objchange/objchange_test.go +++ b/internal/plans/objchange/objchange_test.go @@ -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}))),