-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add IsRequired
validators to list
, set
, and object
validators for Blocks
#107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Do we need to give any consideration to the possibility of these validators being used erroneously? For instance:
func (e *exampleResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"set_nested_attribute": schema.SetNestedAttribute{
Optional: true,
Validators: []validator.Set{
setvalidator.IsRequired(),
},
},
},
}
}
That's a good question. I think we already have the potential of validators conflicting that we don't prevent: "example_string": schema.StringAttribute{
Validators: []validator.String{
stringvalidator.LengthAtLeast(5),
stringvalidator.LengthAtMost(2),
},
}, And as you noted, this PR introduces conflicts between our "built-in" fields As well as this validation is a little special, as it's meant only for the Block types, which don't have |
Bubbled up conversation to our slack, I think this is good to merge for now |
Added labels and assigned to upcoming milestone. |
FYI, this also needs changelog entries: https://github.com/hashicorp/terraform-plugin-framework-validators/blob/main/.github/CONTRIBUTING.md#changelog |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
closes #105
Required
functionality to:ListNestedBlock
SetNestedBlock
SingleNestedBlock
Example validation error:
https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators@v0.9.1-0.20230206221608-25bada52026a
Notes
Attributes
in the error messages, and I updated mine toBlock
. Not sure if this will cause unnecessary confusion?objectvalidator.IsRequired
usage withschema.NestedBlockObject
, but looking at it now, it doesn't seem like that would be useful?