Tuple Type
Note
The tuple type doesn't have associated schema attributes as it has limited real world application. Provider developers will only encounter tuples when handling provider-defined function variadic parameters or dynamic values.
Tuple types store an ordered collection of elements where each element has it's own type. Values must have exactly the same number of elements (no more and no fewer), and the value in each position must match the specified type for that position.
The tuple type is used to express Terraform's tuple type constraint.
Schema Definitions
The tuple type is not supported in schema definitions of provider, data sources, ephemeral resources, or managed resources as it has limited real world application.
Accessing Values
Access types.Tuple
information via the following methods:
(types.Tuple).IsNull() bool
: Returnstrue
if the tuple is null.(types.Tuple).IsUnknown() bool
: Returnstrue
if the tuple is unknown. Returnsfalse
if the number of elements is known, any of which may be unknown.(types.Tuple).Elements() []attr.Value
: Returns the known[]attr.Value
value, ornil
if null or unknown.
Setting Values
Call one of the following to create a types.Tuple
value:
types.TupleNull([]attr.Type) types.Tuple
: A null tuple value with the given element types.types.TupleUnknown([]attr.Type) types.Tuple
: An unknown tuple value with the given element types.types.TupleValue([]attr.Type, []attr.Value) (types.Tuple, diag.Diagnostics)
: A known value with the given element types and values.types.TupleValueMust([]attr.Type, []attr.Value) types.Tuple
: A known value with the given element types and values. Any diagnostics are converted to a runtime panic. This is recommended only for testing or exhaustively tested logic.
In this example, a known tuple value (["one", true, 123]
) is created from framework types: