feat: add role binding data source#75
Conversation
Separated from role binding resource PR #73.
Summary of ChangesHello @markgoddard, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Terraform Cofide provider by adding a new data source for role bindings. This allows users to fetch details of existing role bindings based on various criteria, providing read-only access to these configurations and complementing the existing resource management capabilities. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new data source cofide_connect_role_binding, which is a great addition. The implementation is mostly solid, including the schema, documentation, and test cases. I've identified a couple of areas for improvement in the data source implementation to better align with the Terraform Plugin Framework's best practices and to enhance user experience with better validation. My specific comments are detailed below.
| if len(roleBindings) == 0 { | ||
| resp.Diagnostics.AddError( | ||
| "Error reading role binding", | ||
| "No matching role binding found", | ||
| ) | ||
| return | ||
| } |
There was a problem hiding this comment.
The current implementation returns an error when no role binding is found. According to the Terraform Plugin Framework documentation for data sources, if a resource is not found, the Read function should return with an empty state and no error diagnostics. The framework will then correctly inform the user that the data source did not return any results. Returning an error here will cause the Terraform plan/apply to fail, which is often not the desired behavior for a data source lookup.
Please change the implementation to remove the resource from the state when no role bindings are found.
if len(roleBindings) == 0 {
resp.State.RemoveResource(ctx)
return
}| return | ||
| } |
There was a problem hiding this comment.
The user and group attributes are mutually exclusive. It's good practice to validate this in the provider to give early feedback to the user. A ConfigValidator is the ideal place for this, but adding the check here in the Read function is also a valid approach that prevents invalid configurations.
This check will prevent the provider from sending a potentially invalid filter to the API and will provide a clear error message to the user.
return
}
if config.User != nil && config.Group != nil {
resp.Diagnostics.AddError(
"Conflicting configuration",
"Cannot set both 'user' and 'group' attributes. Please choose only one.",
)
return
}
Separated from role binding resource PR
#73.