Skip to content

Commit

Permalink
Allow MsgPack to marshal optional attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bschaeffer committed Apr 30, 2021
1 parent 26c9b68 commit cb8ed4f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tftypes/value_msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ func marshalMsgPackObject(val Value, typ Type, p *AttributePath, enc *msgpack.En
return unexpectedValueTypeError(p, o, val.value, typ)
}
types := typ.(Object).AttributeTypes
optionalTypes := typ.(Object).OptionalAttributes
keys := make([]string, 0, len(types))
for k := range types {
keys = append(keys, k)
Expand All @@ -565,6 +566,9 @@ func marshalMsgPackObject(val Value, typ Type, p *AttributePath, enc *msgpack.En
ty := types[k]
v, ok := o[k]
if !ok {
if _, isOptional := optionalTypes[k]; isOptional {
continue
}
return p.WithAttributeName(k).NewErrorf("no value set")
}
err := marshalMsgPack(NewValue(String, k), String, p.WithAttributeName(k), enc)
Expand Down

0 comments on commit cb8ed4f

Please sign in to comment.