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

xattr.TypeWithValidate support for list elements (and possibly contents of other collections) #467

Closed
Doridian opened this issue Sep 4, 2022 · 1 comment · Fixed by #481
Labels
enhancement New feature or request

Comments

@Doridian
Copy link
Contributor

Doridian commented Sep 4, 2022

Module version

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

Use-cases

I want to make a list that validates its contents, such as a list of IP addresses

Attempted Solutions

I created an entirely separate type called ValidatedList. This does work, but it prevents anything that is used to dealing with types.List (such as pre-made validators) from interacting with those lists.

See my currently working solutin (albeit without the build-in validators I'd love to be able to use): https://github.com/Doridian/terraform-provider-hexonet/blob/main/hexonet/utils/validated_list.go

Another solution would be to use listvalidator.ValuesAre, but if the value creator (in the case of IPs for example) fails by creating a nil value (such as un-parseable IP), then this cannot work.

Proposal

Implement xattr.TypeWithValidate's Validate function in lists (and possibly other collections)
Add type coercion to collection types and if their element type is a xattr.TypeWithValidate, run its Validate function and actr accordingly.

References

I could not find any prior issue referring to xattr.TypeWithValidate in collections.

@Doridian Doridian added the enhancement New feature or request label Sep 4, 2022
@Doridian Doridian changed the title xattr.TypeWithValidate support for list elements (and contents of other collections) xattr.TypeWithValidate support for list elements (and possibly contents of other collections) Sep 4, 2022
@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 Oct 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