delete a workspace from cli fails when it was created on behalf of another user

To manage a workshop, I wrote some script to create and delete the proper number of users and workspaces. I had no issue to create the workspace on behalf of each user like this:
echo "Please input the number of users you want to create:"
read number

for ((i=0; i<number; i++))
do
coder users create --username user$i --password Password$i --email [email protected] --login-type password
coder create user$i/workspace$i -t AI-101-endpoints -y
done
echo "Please input the number of users you want to create:"
read number

for ((i=0; i<number; i++))
do
coder users create --username user$i --password Password$i --email [email protected] --login-type password
coder create user$i/workspace$i -t AI-101-endpoints -y
done
in the end I have X users with an associated workspace. Now I plan my work after the workshop and so I wrote the equivalent script to remove those users and workspaces.
echo "Please input the number of users you want to delete:"
read number

for ((i=0; i<number; i++))
do
coder delete workspace$i -y
coder users delete user$i
done
echo "Please input the number of users you want to delete:"
read number

for ((i=0; i<number; i++))
do
coder delete workspace$i -y
coder users delete user$i
done
But the command to delete a workspace fails with the error:

Encountered an error running "coder delete", see "coder delete --help" for more information
error: Resource not found or you do not have access to this resource
FAIL

Encountered an error running "coder delete", see "coder delete --help" for more information
error: Resource not found or you do not have access to this resource
FAIL
Did I miss something? side note: why having a different syntax for workspace and not as the others coder <resource> <subcommand>?
11 Replies
Codercord
Codercord6d ago
<#1306212095380946985>
Category
Bug report
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
TitiMoby
TitiMobyOP6d ago
In the meantime I tried to implement this with API calls. but I got 405, DELETE is not allowed on this route
Phorcys
Phorcys6d ago
hey @TitiMoby, it looks like you are missing the user$i/ part in your coder delete command also, i'm pretty sure you don't have to delete workspaces before deleting an user regarding the side note, I'd say that workspaces are kinda the main thing, so it's probably to make commands shorter
TitiMoby
TitiMobyOP6d ago
Ohhhhh you mean
coder delete user$i/workspace$i
coder delete user$i/workspace$i
I’ll have to test it. Did I misread the documentation? It was not really clear. If you want, after my two last events for 2024, I’ll have some time to make some feedback on what I found during my usage of Coder
Atif
Atif5d ago
To delete a workspace for another user you need to provide it's name as user/workspace
Phorcys
Phorcys5d ago
yes! and I would love the feedback!
zounce
zounce5d ago
You do unfortunately, we don't have a way to handle orphaned workspaces currently found this out working on the coderd provider
TitiMoby
TitiMobyOP5d ago
I can confirm that point: you do have to delete workspaces from a user before deleting it. So I can confirm that: - @Phorcys spotted I forgot to include user$i/ - The documentation is a not coherent between create and delete and maybe describe the parameter
name
name
as either <workspace name> or <user name>/<workspace name> in both case (even if I should have though of it by my API version in the near future Considering my initial question, I think I got all I needed. 💞
Phorcys
Phorcys5d ago
coder delete <name> works when it's a workspace owned by the current user basically each workspace is unique on a per user basis
TitiMoby
TitiMobyOP5d ago
I don't know if it's the right place to explain my point of view, but let's give it a try. At first, you have the create command. Documentation says: Usage
coder create [flags] [name]
coder create [flags] [name]
And then you have: Description:
- Create a workspace for another user (if you have permission):

$ coder create <username>/<workspace_name>
- Create a workspace for another user (if you have permission):

$ coder create <username>/<workspace_name>
I would prefer a clear explanation for the name parameter which can be either workspace or user/workspace. Let's say, I have the information needed if I read the create documentation. On the other hand, the delete documentation says: Usage
coder delete [flags] <workspace>
coder delete [flags] <workspace>
And there is no description afterwards explaining the "with or without user" So there is a discrepancy between the two documentation: one is using a parameter name and have clues on what you can put in name, the other one is using workspace and has no detail. I know it might sounds minor, but an old fox like me felt in the trap 😉
Phorcys
Phorcys3d ago
i'll unify that :-)
Want results from more Discord servers?
Add your server