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>?
15 Replies
Codercord
Codercord2mo ago
<#1306212095380946985>
Category
Bug report
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
TitiMoby
TitiMobyOP2mo ago
In the meantime I tried to implement this with API calls. but I got 405, DELETE is not allowed on this route
Phorcys
Phorcys2mo 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
TitiMobyOP2mo 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
Atif2mo ago
To delete a workspace for another user you need to provide it's name as user/workspace
Phorcys
Phorcys2mo ago
yes! and I would love the feedback!
zounce
zounce2mo ago
You do unfortunately, we don't have a way to handle orphaned workspaces currently found this out working on the coderd provider
TitiMoby
TitiMobyOP2mo 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
Phorcys2mo 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
TitiMobyOP2mo 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
Phorcys2mo ago
i'll unify that :-)
TitiMoby
TitiMobyOP2mo ago
/close
Codercord
Codercord2mo ago
@Atif closed the thread.
Phorcys
Phorcys5w ago
Hello @TitiMoby -- I've opened this issue https://github.com/coder/coder/issues/15668
GitHub
fix: unify coder create and coder delete help message · Issue #...
Problem Description The CLI reference for coder create mentions clearly that you can create workspaces for other users, but the reference for coder delete doesn't say anything about other users...
Phorcys
Phorcys4w ago
hello @TitiMoby, the fix has just been merged, the CLI and docs will be updated accordingly in the next release https://github.com/coder/coder/pull/15752#pullrequestreview-2480240111

Did you find this page helpful?