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/float32 below:

Float32 types | Terraform | HashiCorp Developer

Float32 types store a 32-bit floating point number.

By default, float32 from schema (configuration, plan, and state) data are represented in the framework by types.Float32Type and its associated value storage type of types.Float32. These types fully support Terraform's type system concepts that cannot be represented in Go built-in types, such as *float32. 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 float32 value to a schema or nested attribute type:

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

If the float32 value should be a value type of an object attribute type, set the AttrTypes map value to types.Float32Type 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.Float32 in this case.

Access types.Float32 information via the following methods:

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

// Example data model definition
// type ExampleModel struct {
//   ExampleAttribute types.Float32 `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() {
    // ...
}

// myFloat32 now contains a Go float32 with the known value
myFloat32 := data.ExampleAttribute.ValueFloat32()

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

In this example, a known float32 value is created:

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:

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 float32 is directly used to set a float32 attribute value:

var value float32 = 1.23
diags := resp.State.SetAttribute(ctx, path.Root("example_attribute"), value)

In this example, a types.List of types.Float32 is created from a []float32:

listValue, diags := types.ListValueFrom(ctx, types.Float32Type, []float32{1.2, 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