Skip to content

Commit

Permalink
Fix a panic when using DynamicPseudoType attributes in an object
Browse files Browse the repository at this point in the history
  • Loading branch information
kjagiello committed Nov 11, 2021
1 parent d36cd4c commit 0131d41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/116.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Fixed a panic when using DynamicPseudoType attributes in an object.
```
2 changes: 1 addition & 1 deletion tftypes/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func valueFromObject(types map[string]Type, optionalAttrs map[string]struct{}, i
if v.Type() == nil {
return Value{}, NewAttributePath().WithAttributeName(k).NewErrorf("missing value type")
}
if v.Type().Is(DynamicPseudoType) && v.IsKnown() {
if v.Type().Is(DynamicPseudoType) && v.IsKnown() && !v.IsNull() {
return Value{}, NewAttributePath().WithAttributeName(k).NewErrorf("invalid value %s for %s", v, v.Type())
} else if !v.Type().Is(DynamicPseudoType) && !v.Type().UsableAs(typ) {
return Value{}, NewAttributePath().WithAttributeName(k).NewErrorf("can't use %s as %s", v.Type(), typ)
Expand Down
15 changes: 15 additions & 0 deletions tftypes/value_msgpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,21 @@ func TestValueFromMsgPack(t *testing.T) {
value: NewValue(DynamicPseudoType, nil),
typ: DynamicPseudoType,
},
"object-dynamic-null": {
hex: "81a161c0",
value: NewValue(Object{
AttributeTypes: map[string]Type{
"a": DynamicPseudoType,
},
}, map[string]Value{
"a": NewValue(DynamicPseudoType, nil),
}),
typ: Object{
AttributeTypes: map[string]Type{
"a": DynamicPseudoType,
},
},
},
"dynamic-unknown": {
hex: "d40000",
value: NewValue(DynamicPseudoType, UnknownValue),
Expand Down

0 comments on commit 0131d41

Please sign in to comment.