Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept objects with DynamicPseudoType with null values #116

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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