datadrivers / terraform-provider-nexus

Terraform provider for Sonatype Nexus
https://registry.terraform.io/providers/datadrivers/nexus
Mozilla Public License 2.0
119 stars 53 forks source link

Support for `source` when using `nexus_security_user` #371

Open ehuizar1028 opened 1 year ago

ehuizar1028 commented 1 year ago

Is there an existing issue for this?

Community Note

Description

Due to limitations Nexus on Kubernetes has, API calls to query security users seem to randomly timeout when searching across all realms (LDAP, local, etc) when using LDAP, local users, etc. This timeout happens very random.

Could the source argument be added in your next release to be able to have a more precise query to avoid timeouts (a way to increase timeouts during lookups would be a nice to have too).

Thanks!

https://github.com/datadrivers/go-nexus-client/blob/main/nexus3/schema/security/user.go

New or Affected Resource(s)/Data Source(s)

nexus_security_user

Pro feature

Community Plugin

No response

Potential Terraform Configuration

resource "nexus_security_user" "admin" {
  userid    = "admin"
  firstname = "Administrator"
  lastname  = "User"
  email     = "nexus@example.com"
  password  = "admin123"
  roles     = ["nx-admin"]
  status    = "active"
  source    = "internal"
}

References

No response

Edu-DevOps commented 4 weeks ago

In my case this become an issue more than an enhancement:

I have a local Nexus user and a LDAP Nexus user which both users have the same userid

Due to how the provider refresh the terraform resource for the local user, it reads the LDAP user before than the local one which ends in a resource that will never be aligned:

  ~ resource "nexus_security_user" "local_users" {
      + email     = "myemail@test.com"    # TF wants to add the email because the LDAP user doesn't have it
      ~ firstname = "<ldap user firstname>" -> "My" # TF wants to modify the firstname field because the LDAP user firstname differs
        id        = "my-user"
      + lastname  = "User     # TF wants to add lastname field because LDAP user doesn't have it
      ~ roles     = [
          + "my-role",     # TF wants to add a role because LDAP users doesn't have it
        ]
        # (3 unchanged attributes hidden)
    }

This is happening because how the user tf resource is being refreshed is querying the API using only the id as parameter like v1/security/users?userId=my-user and if you have a couple of users with differente source which shares the userid, as my case, the API will give you most than one user.

Potential solution: add the source parameter to the API query to ensure the API gives you 1 result.