terraform-provider-auth0 icon indicating copy to clipboard operation
terraform-provider-auth0 copied to clipboard

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

Open kherock opened this issue 2 years ago • 1 comments

Checklist

  • [X] I have looked into the README and have not found a suitable solution or answer.
  • [X] I have looked into the documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have upgraded to the latest version of this provider and the issue still persists.
  • [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • [X] 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:

https://github.com/auth0/terraform-provider-auth0/blob/21e8c526ed1c7bfd3d889daef4efa5069f66a833/internal/auth0/organization/resource_member.go#L61-L71

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 avatar Feb 29 '24 01:02 kherock

@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!

kherock avatar Apr 10 '24 21:04 kherock

Is there any update on this? Just hit this problem

james-flwls avatar May 20 '24 14:05 james-flwls

@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

kherock avatar May 22 '24 19:05 kherock

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 (https://github.com/auth0/terraform-provider-auth0/pull/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 (https://github.com/auth0/terraform-provider-auth0/pull/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 (https://github.com/auth0/terraform-provider-auth0/pull/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 avatar May 28 '24 08:05 developerkunal

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.

developerkunal avatar May 31 '24 14:05 developerkunal