Skip to content

Conversation

colin-stuart
Copy link
Contributor

@colin-stuart colin-stuart commented Jul 30, 2025

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 the like operator, so the query is WHERE 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 to GetOrgUsersForCurrentOrg which returns more information, including the email. That allows us to then tweak the logic to perform an exact match on email or login.

  • If login is provided: the TF provider iterates through the results of the query to return a single user if an exact match on user.login is found.
  • if email provided: The TF provider now iterates through the results of the query to return a single user if an exact match on user.email is found.

@colin-stuart colin-stuart requested review from a team as code owners July 30, 2025 21:37
Copy link
Contributor

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

@colin-stuart colin-stuart marked this pull request as draft July 30, 2025 21:55
Copy link
Contributor

@volcanonoodle volcanonoodle left a comment

Choose a reason for hiding this comment

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

LGTM! 😄

@cinaglia cinaglia force-pushed the grafana-organization-user-should-filter-results branch from 2397aa0 to 8171106 Compare August 6, 2025 19:49
@cinaglia cinaglia changed the title When multiple organization users found, filter results for an exact match on 'login' When multiple organization users found, filter results for an exact match on email or login Aug 6, 2025
@cinaglia cinaglia marked this pull request as ready for review August 6, 2025 20:34
@cinaglia cinaglia requested a review from volcanonoodle August 6, 2025 20:34
@cinaglia
Copy link
Member

cinaglia commented Aug 6, 2025

FYI Looks like the acceptance tests are failing for an unrelated issue. I've spot checked other recent PRs that have the same issue.

Copy link
Contributor

@volcanonoodle volcanonoodle left a comment

Choose a reason for hiding this comment

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

Great 💯

Copy link
Contributor Author

@colin-stuart colin-stuart left a 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.

@cinaglia cinaglia enabled auto-merge (squash) August 7, 2025 16:11
@cinaglia cinaglia merged commit b39e1c1 into main Aug 7, 2025
31 checks passed
@cinaglia cinaglia deleted the grafana-organization-user-should-filter-results branch August 7, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants