Kaginari / terraform-provider-mongodb

Terraform provider for mongodb instance (selfhosted, AWS documentDB and cloud instances )
MIT License
26 stars 33 forks source link

Updating / Deleting a user (using Terraform) results in `Error: User does not exist` #34

Closed sherifkayad closed 1 year ago

sherifkayad commented 1 year ago

Deleting a user by removing the resource from Terraform results in Error: User does not exist. The same exact thing happens when e.g. we try to update e.g. the username of the user

module.documentdb_init.mongodb_db_user.personalized_user["sherif.k.ayad@gmail.com"]: Destroying... [id=YWRtaW4uc2hlcmlmLmF5YWRAcGFydG5lci5pb25pdHkuZXU=]
╷
│ Error: User does not exist

The following is my config for the user resource:

locals {
  personalized_users = {
     "sherif.k.ayad@gmail.com": {
         username = "sherif.k.ayad@gmail.com"
         password = "some_secure_pass"
         // ... some other stuff 
      }
  }
}

resource "mongodb_db_user" "personalized_user" {
  for_each = local.personalized_users

  auth_database = "admin"
  name          = each.value.username
  password      = each.value.password

  role {
    db   = "my_db_1"
    role = "readWrite"
  }
  role {
    db   = "my_db_2"
    role = "readWrite"
  }
}
sherifkayad commented 1 year ago

Found the reason! I was using usernames with dotes (. & @) characters .. despite that DocumentDB doesn't seem to complain, these were causing issues with the provider. I switched to using underscores (_) instead and the deletion / update of users is working like a charm.