mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
command/jsonstate,plan: fix panic with null values (#23492)
The code responsible for marshalling attribute values was checking for nil values, but not null. Fixes #23485, #23274
This commit is contained in:
parent
211cf08b38
commit
99225b8d76
@ -26,7 +26,7 @@ type stateValues struct {
|
||||
type attributeValues map[string]interface{}
|
||||
|
||||
func marshalAttributeValues(value cty.Value, schema *configschema.Block) attributeValues {
|
||||
if value == cty.NilVal {
|
||||
if value == cty.NilVal || value.IsNull() {
|
||||
return nil
|
||||
}
|
||||
ret := make(attributeValues)
|
||||
|
@ -30,6 +30,18 @@ func TestMarshalAttributeValues(t *testing.T) {
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
cty.NullVal(cty.String),
|
||||
&configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bar"),
|
||||
|
@ -101,9 +101,10 @@ type resource struct {
|
||||
type attributeValues map[string]interface{}
|
||||
|
||||
func marshalAttributeValues(value cty.Value, schema *configschema.Block) attributeValues {
|
||||
if value == cty.NilVal {
|
||||
if value == cty.NilVal || value.IsNull() {
|
||||
return nil
|
||||
}
|
||||
|
||||
ret := make(attributeValues)
|
||||
|
||||
it := value.ElementIterator()
|
||||
|
@ -91,6 +91,18 @@ func TestMarshalAttributeValues(t *testing.T) {
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
cty.NullVal(cty.String),
|
||||
&configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"foo": cty.StringVal("bar"),
|
||||
|
Loading…
Reference in New Issue
Block a user