|
| 1 | +// Package tftypes provides a type system for Terraform configuration and state |
| 2 | +// values. |
| 3 | +// |
| 4 | +// Terraform's configuration and state values are stored using a collection of |
| 5 | +// types. There are primitive types, such as strings, numbers, and booleans, |
| 6 | +// but there are also aggregate types such as lists, sets, tuples, maps, and |
| 7 | +// objects, which consist of multiple values of primitive types aggregated into |
| 8 | +// a single value. There is also a dynamic pseudo-type that represents an |
| 9 | +// unknown type. It is useful for indicating that any type of data is |
| 10 | +// acceptable. |
| 11 | +// |
| 12 | +// Terraform's values map neatly onto either primitives built into Go or types |
| 13 | +// in the Go standard library, with one exception. Terraform has the concept of |
| 14 | +// unknown values, values that may or may not be set at a future date. These |
| 15 | +// are distinct from null values, which indicate a value that is known to not |
| 16 | +// be set, and are mostly encountered when a user has interpolated a computed |
| 17 | +// field into another field; the field that is interpolated into has an unknown |
| 18 | +// value, because the field being interpolated won't have its value known until |
| 19 | +// apply time. |
| 20 | +// |
| 21 | +// To address this, the tftypes package wraps all values in a special Value |
| 22 | +// type. This Value type is capable of holding known and unknown values, |
| 23 | +// interrogating whether the value is known or not, and accessing the concrete |
| 24 | +// value that Terraform sent in the cases where the value is known. A common |
| 25 | +// pattern is to use the Value.IsKnown() method to confirm that a value is |
| 26 | +// known, then to use the Value.As() method to retrieve the underlying data for |
| 27 | +// use. |
| 28 | +// |
| 29 | +// When using the Value.As() method, certain types have built-in behavior to |
| 30 | +// support using them as destinations for converted data: |
| 31 | +// |
| 32 | +// * String values can be converted into strings |
| 33 | +// * Number values can be converted into *big.Floats |
| 34 | +// * Boolean values can be converted into bools |
| 35 | +// * List, Set, and Tuple values can be converted into a slice of Values |
| 36 | +// * Map and Object values can be converted into a map with string keys and |
| 37 | +// Value values. |
| 38 | +// |
| 39 | +// These defaults were chosen because they're capable of losslessly |
| 40 | +// representing all possible values for their Terraform type, with the |
| 41 | +// exception of null values. Converting into pointer versions of any of these |
| 42 | +// types will correctly surface null values as well. |
| 43 | +// |
| 44 | +// Custom, provider-defined types can define their own conversion logic that |
| 45 | +// will be respected by Value.As(), as well, by implementing the |
| 46 | +// FromTerraform5Value method for that type. The FromTerraform5Value method |
| 47 | +// accepts a Value as an argument and returns an error. The Value passed in |
| 48 | +// will be the same Value that Value.As() was called on. The recommended |
| 49 | +// implementation of the FromTerraform5Value method is to call Value.As() on |
| 50 | +// the passed Value, converting it into one of the built-in types above, and |
| 51 | +// then performing whatever type casting or conversion logic is required to |
| 52 | +// assign the data to the provider-supplied type. |
| 53 | +package tftypes |
0 commit comments