mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-20 11:48:24 -06:00
don't try to treat "null" as json in diff output
Trying to decode and write "null" as json will panic, since it decodes to nil.
This commit is contained in:
parent
2c60140cad
commit
0569e39788
@ -496,7 +496,9 @@ func (p *blockBodyDiffPrinter) writeValue(val cty.Value, action plans.Action, in
|
|||||||
// Special behavior for JSON strings containing array or object
|
// Special behavior for JSON strings containing array or object
|
||||||
src := []byte(val.AsString())
|
src := []byte(val.AsString())
|
||||||
ty, err := ctyjson.ImpliedType(src)
|
ty, err := ctyjson.ImpliedType(src)
|
||||||
if err == nil && !ty.IsPrimitiveType() {
|
// check for the special case of "null", which decodes to nil,
|
||||||
|
// and just allow it to be printed out directly
|
||||||
|
if err == nil && !ty.IsPrimitiveType() && val.AsString() != "null" {
|
||||||
jv, err := ctyjson.Unmarshal(src, ty)
|
jv, err := ctyjson.Unmarshal(src, ty)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
p.buf.WriteString("jsonencode(")
|
p.buf.WriteString("jsonencode(")
|
||||||
|
@ -30,6 +30,26 @@ func TestResourceChange_primitiveTypes(t *testing.T) {
|
|||||||
+ resource "test_instance" "example" {
|
+ resource "test_instance" "example" {
|
||||||
+ id = (known after apply)
|
+ id = (known after apply)
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"creation (null string)": {
|
||||||
|
Action: plans.Create,
|
||||||
|
Mode: addrs.ManagedResourceMode,
|
||||||
|
Before: cty.NullVal(cty.EmptyObject),
|
||||||
|
After: cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"string": cty.StringVal("null"),
|
||||||
|
}),
|
||||||
|
Schema: &configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"string": {Type: cty.String, Optional: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RequiredReplace: cty.NewPathSet(),
|
||||||
|
Tainted: false,
|
||||||
|
ExpectedOutput: ` # test_instance.example will be created
|
||||||
|
+ resource "test_instance" "example" {
|
||||||
|
+ string = "null"
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
"deletion": {
|
"deletion": {
|
||||||
|
Loading…
Reference in New Issue
Block a user