File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -21,14 +21,26 @@ import (
2121// terraform-plugin-go and is no longer a valid value.
2222var ErrUnknownDynamicValueType = errors .New ("DynamicValue had no JSON or msgpack data set" )
2323
24+ // NewDynamicValue creates a DynamicValue from a tftypes.Value. You must
25+ // specify the tftype.Type you want to send the value as, and it must be a type
26+ // that is compatible with the Type of the Value. Usually it should just be the
27+ // Type of the Value, but it can also be the DynamicPseudoType.
28+ func NewDynamicValue (t tftypes.Type , v tftypes.Value ) (DynamicValue , error ) {
29+ b , err := v .MarshalMsgPack (t )
30+ if err != nil {
31+ return DynamicValue {}, err
32+ }
33+ return DynamicValue {
34+ MsgPack : b ,
35+ }, nil
36+ }
37+
2438// DynamicValue represents a nested encoding value that came from the protocol.
2539// The only way providers should ever interact with it is by calling its
2640// `Unmarshal` method to retrive a `tftypes.Value`. Although the type system
2741// allows for other interactions, they are explicitly not supported, and will
2842// not be considered when evaluating for breaking changes. Treat this type as
2943// an opaque value, and *only* call its `Unmarshal` method.
30- //
31- // TODO: document how to create a DynamicValue.
3244type DynamicValue struct {
3345 MsgPack []byte
3446 JSON []byte
You can’t perform that action at this time.
0 commit comments