Commit 70e3716
Paddy Carver
Complicate type system.
The old type system was simple, but insufficient. We erased some
necessary complexity by ignoring unknown values. You could represent
them as tftypes.RawValues, but the intended usage of a tftypes.RawValue
is to call its Unmarshal method as close to the boundary of your
provider as possible. Unfortunately, in that situation, we never really
thought through what would happen with unknown values, which can't be
represented in a strongly-typed Go type, they would need to be an
interface or struct of some sort. So that approach wouldn't work, in
practice.
This new approach is to expose tfprotov5.DynamicValues from the protocol
methods, and they have an Unmarshal method that gives you a
tftypes.Value. The DynamicValue is just the msgpack/json bytes, the
Unmarshal method takes the tftypes.Type you want them decoded into, and
returns a tftypes.Value of that type if possible.
tftypes.Value gained some new helper methods, most notably As(), which
lets you convert from the canonical types that JSON and msgpack will
store in the Value into a more friendly type, if that conversion is
possible. So far, the only conversions that are possible is calling the
UnmarshalTerraform5Type method if the destination has one. A future
improvement would be to build in some default conversions for the
builtin Go types and maybe some collection types for tftypes.Values,
like []tftypes.Value or map[string]tftypes.Value. This approach gives us
a more explicit interface that's decoupled from the type we store in the
Value, and it allows us to massage things if we change details or
introduce new types, so there's not a backwards compatibility concern.
Finally, we added a tftypes.Path type, which is used to keep track of
pathing information into values so we can return more useful, specific
errors. It was integrated into the JSON unmarshaling and msgpack
marshaling, but probably could stand to be integrated into the msgpack
unmarshaling and to have an easy, handy conversion into a
tfprotov5.AttributePath. That may require some minor reworking.1 parent e860d96 commit 70e3716
File tree
19 files changed
+1439
-1095
lines changed- tfprotov5
- internal
- fromproto
- toproto
- tftypes
19 files changed
+1439
-1095
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| |||
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
16 | | - | |
| 14 | + | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| |||
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
25 | | - | |
26 | | - | |
| 23 | + | |
| 24 | + | |
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
| 28 | + | |
31 | 29 | | |
32 | 30 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
0 commit comments