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

Can't import or create auth0_organization_member on Organizations with more than 50 members #925

Closed
6 tasks done
kherock opened this issue Feb 29, 2024 · 5 comments
Closed
6 tasks done
Labels
🪲 bug Something isn't working

Comments

@kherock
Copy link

kherock commented Feb 29, 2024

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have upgraded to the latest version of this provider and the issue still persists.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

I have an Organization with many members that I am currently trying to associate new members using the auth0_organization_member. When I try to add new members, I get the "inconsistent result after apply" error with

│ "provider[\"registry.terraform.io/auth0/auth0\"]" produced an unexpected new value: Root resource was present, but now absent.

This only happens when there are at least 50 members in the organization. I expect that this correlates with the default page size for the Go SDK. Currently, there is only one query to find organization members, and existence is checked by a simple loop over the results:

members, err := api.Organization.Members(ctx, organizationID)
if err != nil {
return diag.FromErr(internalError.HandleAPIError(data, err))
}
userID := data.Get("user_id").(string)
for _, member := range members.Members {
if member.GetUserID() == userID {
return nil
}
}

Expectation

Terraform should be able to add auth0_organization_members to Organizations of arbitrary size. Rather than checking for an ID in every page of the member list, I think it would be better to check that the GET /api/v2/organizations/{id}/members/{user_id}/roles endpoint doesn't return a 404 response. Alternatively, the organization_id: field could be used for a Lucene search on the user search endpoint.

Reproduction

  1. Create an Organization with at least 50 members. I believe this is the only requirement since Auth0 seems to order members in order of insertion. It might be necessary to go beyond this - my organization has around 190 members currently.
  2. add a new auth0_organization_member resource
     resource "auth0_organization_member" "bulk_test_users" {
       count = length(auth0_user.bulk_test_users)
     
       organization_id = "{id}"
       user_id         = auth0_user.bulk_test_users[count.index].user_id
     }

Auth0 Terraform Provider version

1.2.0

Terraform version

1.3.7

@kherock kherock added the 🪲 bug Something isn't working label Feb 29, 2024
@kherock
Copy link
Author

kherock commented Apr 10, 2024

@sergiught sorry for the ping, I've just noticed that the repository has been quiet for some time and was wondering if you had any idea when maintainers will be able to look at some of the recent issues like this one.

In the meantime, I am going to open a PR for this and operate on my own fork!

@james-flwls
Copy link

Is there any update on this? Just hit this problem

@kherock
Copy link
Author

kherock commented May 22, 2024

@james-flwls I've published binaries for my patch here, if you're interested.

https://github.com/kherock/terraform-provider-auth0/releases/tag/v1.2.1-beta.0

@developerkunal
Copy link
Contributor

Hey @kherock,

I hope you're doing well and having a nice day!

I apologize for the delayed response.

I just wanted to provide you with an update regarding your PR (#946). While we initially considered your approach, upon further review, we realized that it might be a bit of a workaround. Your idea of checking for specific roles to determine organization membership is a bit indirect.

Instead, we've decided to pursue a different approach, as outlined in PR (#961). This new approach involves using checkpoint pagination through the members endpoint, which we believe is a more direct and consistent solution.

Given this direction, since we've already merged a similar solution in PR (#961), we won't be merging your PR. However, I want to sincerely thank you for your contribution and effort.

If you have any questions or concerns, feel free to reach out. Thanks again for your contribution!

Best Regards,

@developerkunal
Copy link
Contributor

Hi @kherock ,

Great news! The issue has been fixed in version 1.2.1. Please take a moment to review, and feel free to reach out if you encounter any further issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working
Projects
None yet
3 participants