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

Boolean types | Terraform | HashiCorp Developer

Bool types store a boolean true or false value.

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

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

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

Access types.Bool information via the following methods:

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

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

// myBool now contains a Go bool with the known value
myBool := data.ExampleAttribute.ValueBool()

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

In this example, a known bool value is created:

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

A Go built-in bool, *bool (only with typed nil, (*bool)(nil)), or type alias of bool such as type MyBoolType bool can be used instead.

In this example, a bool is directly used to set a bool attribute value:

diags := resp.State.SetAttribute(ctx, path.Root("example_attribute"), true)

In this example, a types.List of types.Bool is created from a []bool:

listValue, diags := types.ListValueFrom(ctx, types.BoolType, []bool{true, false})

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