Int64 Type
Tip
Use Float64 Type for 64-bit floating point numbers. Use Number Attribute for arbitrary precision numbers.
Int64 types store a 64-bit integer number.
By default, int64 from schema (configuration, plan, and state) data are represented in the framework by types.Int64Type
and its associated value storage type of types.Int64
. These types fully support Terraform's type system concepts that cannot be represented in Go built-in types, such as *int64
. Framework types can be extended by provider code or shared libraries to provide specific use case functionality.
Schema Definitions
Use one of the following attribute types to directly add a int64 value to a schema or nested attribute type:
Schema Type | Attribute Type |
---|---|
Data Source | schema.Int64Attribute |
Provider | schema.Int64Attribute |
Resource | schema.Int64Attribute |
Ephemeral Resource | schema.Int64Attribute |
If the int64 value should be the element type of a collection attribute type, set the ElemType
field to types.Int64Type
or the appropriate custom type.
If the int64 value should be a value type of an object attribute type, set the AttrTypes
map value to types.Int64Type
or the appropriate custom type.
Accessing Values
Tip
Review the attribute documentation to understand how schema-based data gets mapped into accessible values, such as a types.Int64
in this case.
Access types.Int64
information via the following methods:
(types.Int64).IsNull() bool
: Returns true if the int64 is null.(types.Int64).IsUnknown() bool
: Returns true if the int64 is unknown.(types.Int64).ValueInt64() int64
: Returns the known int64, or0
if null or unknown.(types.Int64).ValueInt64Pointer() *int64
: Returns a int64 pointer to a known value,nil
if null, or a pointer to0
if unknown.
In this example, a int64 value is checked for being null or unknown value first, before accessing its known value:
Setting Values
Call one of the following to create a types.Int64
value:
types.Int64Null()
: A null int64 value.types.Int64Unknown()
: An unknown int64 value.types.Int64Value(int64)
: A known value.types.Int64PointerValue(*int64)
: A known value.
In this example, a known int64 value is created:
Otherwise, for certain framework functionality that does not require types
implementations directly, such as:
(tfsdk.State).SetAttribute()
types.ListValueFrom()
types.MapValueFrom()
types.ObjectValueFrom()
types.SetValueFrom()
Numbers can be automatically converted from the following Go types, pointers to these types, or any aliases of these types, such type MyNumber int
:
int
,int8
,int16
,int32
,int64
uint
,uint8
,uint16
,uint32
,uint64
float32
,float64
*big.Int
,*big.Float
An error will be returned if the value of the number cannot be stored in the numeric type supplied because of an overflow or other loss of precision.
In this example, a int64
is directly used to set a int64 attribute value:
In this example, a types.List
of types.Int64
is created from a []int64
:
Extending
The framework supports extending its base type implementations with custom types. These can adjust expected provider code usage depending on their implementation.