A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.hashicorp.com/terraform/plugin/framework/handling-data/types/number below:

Number types | Terraform | HashiCorp Developer

Number types store an arbitrary precision (generally more than 64-bit, up to 512-bit) number.

By default, number from schema (configuration, plan, and state) data are represented in the framework by types.NumberType and its associated value storage type of types.Number. These types fully support Terraform's type system concepts that cannot be represented in Go built-in types, such as *big.Float. Framework types can be extended by provider code or shared libraries to provide specific use case functionality.

Use one of the following attribute types to directly add a number value to a schema or nested attribute type:

If the number value should be the element type of a collection attribute type, set the ElemType field to types.NumberType or the appropriate custom type.

If the number value should be a value type of an object attribute type, set the AttrTypes map value to types.NumberType or the appropriate custom type.

Tip

Review the attribute documentation to understand how schema-based data gets mapped into accessible values, such as a types.Number in this case.

Access types.Number information via the following methods:

In this example, a number value is checked for being null or unknown value first, before accessing its known value:

// Example data model definition
// type ExampleModel struct {
//   ExampleAttribute types.Number `tfsdk:"example_attribute"`
// }
//
// This would be filled in, such as calling: req.Plan.Get(ctx, &data)
var data ExampleModel

// optional logic for handling null value
if data.ExampleAttribute.IsNull() {
    // ...
}

// optional logic for handling unknown value
if data.ExampleAttribute.IsUnknown() {
    // ...
}

// myNumber now contains a Go *big.Float with the known value
myNumber := data.ExampleAttribute.ValueBigFloat()

Call one of the following to create a types.Number value:

In this example, a known number value is created:

types.NumberValue(big.NewFloat(1.23))

Otherwise, for certain framework functionality that does not require types implementations directly, such as:

Numbers can be automatically converted from the following Go types, pointers to these types, or any aliases of these types, such type MyNumber int:

In this example, a *big.Float is directly used to set a number attribute value:

diags := resp.State.SetAttribute(ctx, path.Root("example_attribute"), big.NewFloat(1.23))

In this example, a types.List of types.Number is created from a []*big.Float:

listValue, diags := types.ListValueFrom(ctx, types.NumberType, []*big.Float{big.NewFloat(1.2), big.NewFloat(2.4)})

The framework supports extending its base type implementations with custom types. These can adjust expected provider code usage depending on their implementation.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4