Consider Go Pointer Value Constructors and Getters for Primitive Types #649
Labels
enhancement
New feature or request
types
Issues and pull requests about our types abstraction and implementations.
Milestone
Module version
Use-cases
Provider developers with terraform-plugin-framework are typically encouraged to work with
types
package types for a consistent data model across Terraform configuration, plan, and state data. Configuration and plan data may contain unknown values, which an important distinction from other type systems, including Go's built-in types.However, API-based SDKs opposite of Terraform may prefer pointer-based Go types for data handling. For example:
ec2.CreateVpcInput
/ec2.CreateVpcOutput
)servers.Server
)github.Repository
)Given the current
types
package design which has methodologies for working directly with non-pointer Go types, it can therefore require extra pointer-based logic to correctly work with data between Terraform and the API SDK.Attempted Solutions
These examples assume
*bool
API client value handling andschema.BoolAttribute
/types.Bool
on the Terraform side.Proposal
This proposal covers the following types in the framework type system:
basetypes.Bool
bool
basetypes.Float64
float64
basetypes.Int64
int64
basetypes.String
string
In the
types/basetypes
package, createNew{FT}PointerValue(*GT)
value creator functions. For example:In the
types
package, wrapper functions would be created to use to their basetypes equivalent similar to the other value creator function aliases. For example:In the
types/basetypes
package, createfunc (t {FT}) Value{GT}Pointer() *{GT}
getter methods. For example:Note that this method implementation is similar to the existing
func (t {FT}) Value{GT}() {GT}
getter methods, where the design is intentionally skewed to provide a potentially invalid answer in the name of simplicity rather than introduce a seconddiag.Diagnostics
return which must always be handled (or worse and forbidden in our typical design decisions, a panic). The non-pointer getter methods return the Go type's zero-value in the case of null and unknown. Provider developers are expected to check against a value's unknown state prior to these methods and Terraform will typically raise its own error should there be a data consistency issue.These new functions and methods should enable provider code such as:
References
The text was updated successfully, but these errors were encountered: