Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attr: Add ValueFromFramework and ToFrameworkValue Interface Functions to attr.Value #535

Closed
bendbennett opened this issue Nov 11, 2022 · 1 comment · Fixed by #536
Closed
Labels
enhancement New feature or request

Comments

@bendbennett
Copy link
Contributor

Module version

github.com/hashicorp/terraform-plugin-framework v0.15.0

Use-cases

A first step required for making the use of custom types for nested attributes feasible requires a mechanism for converting to/from the framework type (e.g., types.List).

Attempted Solutions

Using an interface implemented by custom types that is specific to the framework type (e.g., types.List) that they embed and then using type assertion to determine if the type being used is either a framework type (e.g., types.List) or a type that implements an interface that gives access to the framework type (e.g., types.List) embedded in the custom type.

Proposal

Introduce separate interfaces for each of the framework types that can be implemented by custom types to allow access to the embedded type and to obtain an instance of the custom type by passing the framework type.

package attr

type ListType interface {
  attr.Type // common bits

  ValueFromFramework(context.Context, types.List) (Value, diag.Diagnostics)
}

type ListValue interface {
  attr.Value

  ToFrameworkValue(context.Context) (types.List, diag.Diagnostics)
}

Once these interfaces are in place then custom types that embed framework types (e.g., types.List) can be created and used in place of framework types.

References

@bendbennett bendbennett added the enhancement New feature or request label Nov 11, 2022
bendbennett added a commit that referenced this issue Nov 11, 2022
… types.ListType and types.List (value), respectively (#535)
bendbennett added a commit that referenced this issue Nov 11, 2022
… types.MapType and types.Map (value), respectively (#535)
bendbennett added a commit that referenced this issue Nov 11, 2022
… types.SetType and types.Set (value), respectively (#535)
bendbennett added a commit that referenced this issue Nov 11, 2022
… types.ObjectType and types.Object (value), respectively (#535)
bendbennett added a commit that referenced this issue Nov 11, 2022
… primitive types and primitive values, respectively (#535)
bendbennett added a commit that referenced this issue Nov 14, 2022
bendbennett added a commit that referenced this issue Nov 14, 2022
bendbennett added a commit that referenced this issue Nov 14, 2022
… attribute plan modification and attribute validation for custom nested attribute types (#535)
bendbennett added a commit that referenced this issue Nov 15, 2022
* Adding ValueFromFramework and ToFrameworkValue interface functions to types.ListType and types.List (value), respectively (#535)

* Adding ValueFromFramework and ToFrameworkValue interface functions to types.MapType and types.Map (value), respectively (#535)

* Adding ValueFromFramework and ToFrameworkValue interface functions to types.SetType and types.Set (value), respectively (#535)

* Adding ValueFromFramework and ToFrameworkValue interface functions to types.ObjectType and types.Object (value), respectively (#535)

* Adding ValueFromFramework and ToFrameworkValue interface functions to primitive types and primitive values, respectively (#535)

* Refactoring interface names to use -able suffix (#535)

* Adding Go documentation and refactoring to return type-specific interfaces from ValueFrom<type> functions (#535)

* Adding further Go documentation (#535)

* Apply suggestions from code review

Co-authored-by: Brian Flad <bflad417@gmail.com>

* Amending Go documentation (#535)

* Adding changelog, amending Go documentation and adding unit tests for attribute plan modification and attribute validation for custom nested attribute types (#535)

Co-authored-by: Brian Flad <bflad417@gmail.com>
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant