Closed
Description
When a user created via the coderd provider is removed outside of terraform, the plan fails because it cannot find the user.
resource "coderd_user" "user" {
username = "myuser"
email = "myuser@myorg.com"
name = "My User"
roles = []
login_type = "oidc"
}
╷
│ Error: Client Error
│
│ with coderd_user.user,
│ on users.tf line 1, in resource "coderd_user" "user":
│ 1: resource "coderd_user" "user" {
│
│ Unable to get current user, got error: GET
│ https://<REDACTED url>/api/v2/users/<REDACTED user id>:
│ unexpected status code 400: "user" must be an existing uuid or username.
│ Error: queried user="<REDACTED user id>"
╵
I would have expected the provider to mark this as deleted instead of running into an error
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Plan fails when user was deleted outside of terraform[/-][+]Resource `coderd_user`: Plan fails when user was deleted outside of terraform[/+]ethanndickson commentedon Apr 14, 2025
Unlike all the other resources, it looks like we send a
400
if the User is missing, instead of a 404, so this was missed by #102..I'll update the provider to handle that.
However, I can't reproduce your issue exactly. FWICT
api/v2/users/{ID}
queries continue to work after the user is deleted, as the DB query doesn't filter out users wheredeleted
is true. What version of Coder are you running?EDIT: This is just because I'm authorized as Owner. Not sure if that's by design, but it kinda makes sense.
michvllni commentedon Apr 14, 2025
I'm using coder version 2.20.0 with coder provider version 2.3.0 and coder provider version 0.0.10
However, I might have misunderstood something. I didn't know that coder doesnt completely remove the just but just adds a deleted flag.
In my case, I reset my database to have a fresh start as I broke some stuff and wanted to test a green-field-ish deployment.
So the user actually was not in the database, but still in the terraform state
fix: handle user deletion config drift (#209)