Skip to content

Commit 88b4680

Browse files
fix null dynamic type handling
1 parent 478e3cb commit 88b4680

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pkg/valueshim/tftype_json.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,19 @@ func jsonMarshalDynamicPseudoType(v tftypes.Value, _ tftypes.Type, p *tftypes.At
9797
if err != nil {
9898
return nil, p.NewError(err)
9999
}
100-
valJSON, err := jsonMarshal(v, valType, p)
101-
if err != nil {
102-
return nil, p.NewError(err)
103-
}
104-
marshalledValJSON, err := json.Marshal(valJSON)
105-
if err != nil {
106-
return nil, p.NewError(err)
100+
101+
var marshalledValJSON interface{}
102+
// The null case is handled separately to prevent infinite recursion.
103+
if v.IsNull() {
104+
marshalledValJSON = "null"
105+
} else {
106+
valJSON, err := jsonMarshal(v, v.Type(), p)
107+
if err != nil {
108+
return nil, p.NewError(err)
109+
}
110+
marshalledValJSON, err = json.Marshal(valJSON)
107111
}
112+
108113
return json.RawMessage(fmt.Sprintf(`{"value": %s, "type": %s}`, marshalledValJSON, typeJSON)), nil
109114
}
110115

0 commit comments

Comments
 (0)