Terraform Plugin Framework Version 1.2.0 Released

Hello, Provider Developers! :wave:

The Terraform Development Experience team at HashiCorp is excited to announce terraform-plugin-framework version 1.2.0 which was released today. This release contains resource default attribute value support, easier conversion of Go pointer types to/from framework value types, and some bug fixes. Refer to the changelog for a full listing of provider development related items in this release and the updated Go package documentation is available.

Resource Default Attribute Values

When the framework was originally implemented, generic and extensible functionality was provided for plan modification. It was believed that this generic functionality could cover all valid use cases for resources, such as setting computed attribute values as unknown or known with a new value, marking a resource for replacement, and handling API-defined default values. As provider developers tried to work with default values, certain interactions between how Terraform and framework handled plans could cause differing plan behaviors based on what changes were being made in the configuration. To prevent these potentially confusing situations, built-in resource default attribute value support has been added to the framework.

To take advantage of this functionality, each of the framework-defined resource schema attribute types now include a Default field. This field generally will be implemented with one of the framework-defined default value functions, although provider developers can also extend the available interfaces to implement custom default handling, such as defaults based on environment variables. Existing provider-defined plan modifiers for default values should be replaced with this framework-defined support as it can prevent confusing planning behaviors.

In this example, the string attribute value will default to “Happy Terraforming” if its configuration is null:

// Typically within a resource Schema() method.
    // Practitioners may set the value, this is not required for Default support
    Optional: true,
    // Provider may set the value, this is required for Default support
    Computed: true,
    // If the configuration value is not set (null), plan it as "Happy Terraforming"
    Default: stringdefault.StaticString("Happy Terraforming"),

    // ... other attribute configuration ...

More complete information can be found in the new resource default attribute value documentation. Please note that this support is only available for resources as this is the only Terraform concept that implements planning today. Data sources should continue to handle any potential default values in the Read method logic and providers should continue to handle any potential defaults in the Configure method logic, same as before.

Framework Type Pointer Handling

The framework type system, which differs from the standard Go type system because it must support Terraform’s unknown values and other future concepts, has been enhanced to support easier conversions to/from Go pointer types for primitive types (*bool, *float64, *int64, and *string).

In this example, the prior Go pointer type logic is shown:

// Prior conversion from Go *bool to framework types.Bool
if client.Value == nil {
  data.Value = types.BoolNull()
} else {
  data.Value = types.BoolValue(*client.Value)

// Prior conversion from framework types.Bool to Go *bool
if data.Value.IsNull() {
  client.Value = nil
} else {
  value := data.Value.ValueBool()
  client.Value = &value

In this example, the new Go pointer type logic is shown:

// New conversion from Go *bool to framework types.Bool
data.Value = types.BoolPointerValue(client.Value)

// New conversion from framework types.Bool to Go *bool
client.Value = data.Value.ValueBoolPointer()


If you have any feedback about this release, or framework provider development in general, please let us know. Questions can be asked in HashiCorp Discuss and any bug reports, feature requests, or documentation suggestions can be submitted in GitHub. Happy Terraforming!