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

Add plugin framework conflics_with and at_least_one_of to instance #181

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

Iduoad
Copy link
Contributor

@Iduoad Iduoad commented Dec 5, 2024

I added declarative validator built-in the provider framework instead of imperatively checking in Validate function.

@Iduoad
Copy link
Contributor Author

Iduoad commented Dec 5, 2024

Closes #180

Copy link
Collaborator

@breml breml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we would conclude to move ahead with this PR, please also remove the function atMostOneOf, since it is no longer used anywhere.

@@ -116,6 +117,21 @@ func (r InstanceResource) Schema(_ context.Context, _ resource.SchemaRequest, re
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the formatting with gofmt. In Go indentation is done with tab (and not spaces).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

path.MatchRoot("source_file"),
}...
),
stringvalidator.AtLeastOneOf(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation enforces atMostOneOf, which is not the same as AtLeastOneOf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the AtLeastOneOf validator. I think ConflictsWith is enough to replicate atMostOneOf.

@maveonair
Copy link
Member

@Iduoad do you would like to have some help to finish this pull request?

@Iduoad Iduoad changed the title [Draft] Add plugin framework conflics_with and at_least_one_of to instance Add plugin framework conflics_with and at_least_one_of to instance Mar 9, 2025
Validators: []validator.Object{
objectvalidator.ConflictsWith(
path.Expressions{
path.MatchRoot("image"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be omitted since the ConflictWith validation is already defined in the image. Kept it for readability.

Not sure if is this the correct way to do it.

@Iduoad
Copy link
Contributor Author

Iduoad commented Mar 9, 2025

@maveonair I rebased on the latest commit on main, run gofmt and went through the changes again. PR is ready for review.

@Iduoad Iduoad force-pushed the issue-180 branch 2 times, most recently from ec8dec3 to 3fca061 Compare March 9, 2025 23:42
* Replaces manual mutual exclusiveness validation with ConflictsWith
Validator
* Upgrade terraform-plugin-framework-validators module to 0.17.0 to
fix validation bug.
hashicorp/terraform-plugin-framework-validators#251

Signed-off-by: Mohammed Daoudi <[email protected]>
@Iduoad
Copy link
Contributor Author

Iduoad commented Mar 10, 2025

Fixed the failing test and added the signoff in the commit message.

@stgraber
Copy link
Member

@maveonair I'll leave it to you to review/merge, just nudged the tests into all going green :)

@maveonair maveonair enabled auto-merge March 10, 2025 16:25
@maveonair maveonair merged commit dc70e0e into lxc:main Mar 10, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants