-
Notifications
You must be signed in to change notification settings - Fork 268
When multiple organization users found, filter results for an exact match on email or login #2285
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
When multiple organization users found, filter results for an exact match on email or login #2285
Conversation
… exact match on 'login'
In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically. |
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! 😄
internal/resources/grafana/data_source_organization_user_test.go
Outdated
Show resolved
Hide resolved
2397aa0
to
8171106
Compare
FYI Looks like the acceptance tests are failing for an unrelated issue. I've spot checked other recent PRs that have the same issue. |
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.
Great 💯
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.
I can't approve @cinaglia's changes since this is my own PR, but the changes look good.
Part of https://github.com/grafana/support-escalations/issues/17635
Why?
Querying the grafana_organization_user resource from the terraform provider gets all users within the current organization in Grafana. The
SearchOrgUsers
sql query uses thelike
operator, so the query isWHERE email LIKE '%[[email protected]](mailto:[email protected])%'
and the result can include multiple users. Currently, if multiple users are returned in the query, the TF provider returns an error.Fix
The fix relies on switching from
GetOrgUsersForCurrentOrgLookup
over toGetOrgUsersForCurrentOrg
which returns more information, including theemail
. That allows us to then tweak the logic to perform an exact match onemail
orlogin
.login
is provided: the TF provider iterates through the results of the query to return a single user if an exact match onuser.login
is found.email
provided: The TF provider now iterates through the results of the query to return a single user if an exact match onuser.email
is found.