Create a dedicated workspace for each user

I am investigating to see if I would be able to replace Gitpod with Coder for my workshop needs. A first test for me can be a conference I have from 8 to 10th July. I have a workshop with something like 20 attendees. I already know how to have my custom docker image (at least if I use DockerHub and for now it's ok) on my own Coder (using Kubernetes) What I need now is to be able to prepare 20 accounts, with 20 dedicated workspaces. My question: is possible to create a workspace for a specific user (CLI or API is fine)?
53 Replies
Codercord
Codercord7mo ago
<#1252546885466587237>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
TitiMoby
TitiMobyOP7mo ago
for the creation part, my eyes were jumping over the "create" word in the CLI part of the doc because my brain was looking for "create workspace" 🙂 For those reading this post in search of the same thing, it is as simple as
coder create <username>/<workspace_name> -t <template_name>
coder create <username>/<workspace_name> -t <template_name>
now I need to see the permissions of the user allow them to just connect to the workspace and nothing else, and what kind of URL I can share to them. the create command fails. here is what I've done
$ coder templates list [11:36:30]
NAME LAST UPDATED USED BY
debug-coder June 18, 2024 1 active developer
$ coder templates list [11:36:30]
NAME LAST UPDATED USED BY
debug-coder June 18, 2024 1 active developer
to have the name of the template then:
coder create thierry/workshop_ia -t debug-coder
coder create thierry/workshop_ia -t debug-coder
with all default values as per the web UI (which works) the result and error is:
The number of CPU cores

> 2 Cores
Home disk size
The size of the home disk in GB

> Enter a value (default: "10"):
Memory
The amount of memory in GB

> 2 GB
Planning workspace...
=== ✔ Queued [0ms]
==> ⧗ Running
==> ⧗ Running
=== ✔ Running [32ms]
==> ⧗ Setting up
=== ✔ Setting up [154ms]
==> ⧗ Detecting persistent resources
=== ✔ Detecting persistent resources [8849ms]
==> ⧗ Cleaning Up
=== ✘ Cleaning Up [35ms]
=== ✘ Cleaning Up [132ms]
Encountered an error running "coder create", see "coder create --help" for more information
error: prepare build: dry-run workspace: run dry-run provision job: terraform plan: exit status 1
FAIL
The number of CPU cores

> 2 Cores
Home disk size
The size of the home disk in GB

> Enter a value (default: "10"):
Memory
The amount of memory in GB

> 2 GB
Planning workspace...
=== ✔ Queued [0ms]
==> ⧗ Running
==> ⧗ Running
=== ✔ Running [32ms]
==> ⧗ Setting up
=== ✔ Setting up [154ms]
==> ⧗ Detecting persistent resources
=== ✔ Detecting persistent resources [8849ms]
==> ⧗ Cleaning Up
=== ✘ Cleaning Up [35ms]
=== ✘ Cleaning Up [132ms]
Encountered an error running "coder create", see "coder create --help" for more information
error: prepare build: dry-run workspace: run dry-run provision job: terraform plan: exit status 1
FAIL
Phorcys
Phorcys7mo ago
hey @Thierry Chantier, any reason for not letting the users create it themselves ? well I guess if it's a workshop it's a better experience if they don't need to create it themselves what version of Coder are you running ? might be a stupid question but did you input "2 GB" or "2" ?
TitiMoby
TitiMobyOP7mo ago
I'm not at work now, will check tomorrow morning. But I'm pretty sure I have done a helm upgrade today It was from the interactive shell. For now it is not important, I'll tune proper RAM needs later. The same workspace is launched from the web UI
Phorcys
Phorcys7mo ago
I meant is it a multiselect or user input ? I was thinking maybe it's not getting the same data into the template than with the web does the workspace get created afterwards ?
Phorcys
Phorcys7mo ago
there's a GH issue regarding this problem and it seems the workspace is still getting created https://github.com/coder/coder/issues/12282
GitHub
Issue creating workspaces via the CLI · Issue #12282 · coder/coder
After sending workspace parameters, the workspace begins creation process, but it stops after a while with error: STDERR: Encountered an error running "coder create" prepare build: dry-ru...
TitiMoby
TitiMobyOP7mo ago
I will check this issue tomorrow. I’m quite sure it did not appeared afterwards.
Phorcys
Phorcys7mo ago
alright, another thing you might want to do is check the provisionerd logs to see if there's anything interesting in there @Atif do you have any idea on how we can make the CLI spit out some debug logs for this?
TitiMoby
TitiMobyOP7mo ago
version is v2.11.2+d53c94b I found how to start it from the CLI but I have no idea on where to check
provisionerd
provisionerd
logs
Phorcys
Phorcys7mo ago
i think the provisionerd logs should be available from the Coder server's logs so the pod called coderd or something like that hey @Thierry Chantier, any luck?
TitiMoby
TitiMobyOP7mo ago
I ended my week at Voxxed days conference. no time for it. But I remember this discord act as support ticketing, so I will see tomorrow if I can close my two topics, then open new question later when I will have enough time to follow up
Phorcys
Phorcys7mo ago
sure thing! you can use the /close command in those threads, feel free to @ me when opening a new one though your issue really seems like a bug
TitiMoby
TitiMobyOP4mo ago
after conferences time and holidays, I'm back on the topic. I upgraded to
Coder v2.14.2+d1cd784
Coder v2.14.2+d1cd784
but I still have the error. I did not find any information in the documentation to properly access provisionerd logs.
sharkymark
sharkymark4mo ago
@Thierry Chantier sorry if I missed this, but did you enter 2 or 2GB? Pasting the template here (sanitize it) can help @Phorcys if you want to make it really simple, just hardcode the CPU/Mem/Disk quantities in the template and not make them Coder parameters. If you give a choice, they always take the bigger ones.
TitiMoby
TitiMobyOP4mo ago
No worries. I will check on Monday so for the values, I did not typed them as it is already in the starter template and only selected in the cli. To avoid any confusion, I modified my template to remove such parameters as I won't use them in the end. still the same error and I don't know where to look to read logs. I'm copying here the template, it comes from kubernetes starter template
TitiMoby
TitiMobyOP4mo ago
sharkymark
sharkymark4mo ago
since you're in kubernetes, are there any remnants like a pod kubectl get pods -n coder and if so, get logs kubectl logs <pod name> -n coder or describe like if crashloop backoff kubectl describes pods <pod name> -n coder
TitiMoby
TitiMobyOP4mo ago
I thought @Phorcys was referring to a specific daemon and was looking for dedicated logs access. The only logs I found in the pod logs is :
2024-09-02 15:01:55.357 [info] terraform: unpacking template source archive session_id=f4b36658-54c0-410f-8fca-752016dfd70d size_bytes=20480
2024-09-02 15:01:55.446 [info] terraform: clean stale Terraform plugins cache_path=/home/coder/.cache/coder/provisioner-2/tf
2024-09-02 15:02:01.283 [info] provisionerd-coder-5d5b5dbbd5-pmzcs-2.runner: dry-run provision failure job_id=dd14a92f-475f-4228-b8fe-e73fcde2b840 error="terraform plan: exit status 1"
2024-09-02 15:02:01.311 [info] terraform: recv done on Session session_id=f4b36658-54c0-410f-8fca-752016dfd70d error=EOF
2024-09-02 15:01:55.357 [info] terraform: unpacking template source archive session_id=f4b36658-54c0-410f-8fca-752016dfd70d size_bytes=20480
2024-09-02 15:01:55.446 [info] terraform: clean stale Terraform plugins cache_path=/home/coder/.cache/coder/provisioner-2/tf
2024-09-02 15:02:01.283 [info] provisionerd-coder-5d5b5dbbd5-pmzcs-2.runner: dry-run provision failure job_id=dd14a92f-475f-4228-b8fe-e73fcde2b840 error="terraform plan: exit status 1"
2024-09-02 15:02:01.311 [info] terraform: recv done on Session session_id=f4b36658-54c0-410f-8fca-752016dfd70d error=EOF
Phorcys
Phorcys4mo ago
oh yeah no sorry provisionerd is ran by the Coder daemon oh okay, it's a multiselect @Thierry Chantier, just to confirm, has it ever worked in the past?
TitiMoby
TitiMobyOP4mo ago
I never had it working. I mean of course the create action from the cli
Phorcys
Phorcys4mo ago
alright, i think i might know why i'll do some testing on my end to confirm @Thierry Chantier how are you deploying Coder? I have tried with your template (which seems to just be the default k8s template?) and it works properly on my end. I have deployed Coder through Helm in a dedicated coder workspace.
Phorcys
Phorcys4mo ago
I have configured the template accordingly to how I deployed Coder, so I set the namespace to coder
No description
Phorcys
Phorcys4mo ago
could you restart Coder with the following environment variables and retry to start your workspace? TF_LOG=debug CODER_VERBOSE=true CODER_PROVISIONER_DAEMON_VERBOSE=true These variables respectively do the following things : 1. Enable debug logs for Terraform 2. Enable more verbose logs for Coder 3. Enable more verbose logs for provisionerd, unsure whether it is useful since you don't run provisionerd standalone let me know how this goes, maybe we can plan a 1:1 call if needed.
TitiMoby
TitiMobyOP4mo ago
I’ll do that tomorrow, and answer all your questions. Thanks a lot
Phorcys
Phorcys4mo ago
feel free to ping me!
TitiMoby
TitiMobyOP4mo ago
So, here the status and answers. First, I deploy Coder using the Helm method on a Kubernetes at my company, OVHcloud. It is a managed Kubernetes cluster, the same we provide to our cusomer. I plan to use Coder in workshop with my team when we go to conferences. I applied your env variables and I have clues now. First, using the CLI I now have this error:
2024-09-03 10:10:22.139+02:00 coder_app.code-server: Plan to create
2024-09-03 10:10:22.140+02:00 Plan: 2 to add, 0 to change, 0 to destroy.
2024-09-03 10:10:22.144+02:00 Error: metadata.0.name a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
2024-09-03 10:10:22.144+02:00 on main.tf line 132, in resource "kubernetes_persistent_volume_claim" "home":
2024-09-03 10:10:22.144+02:00 132: name = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}-home"
2024-09-03 10:10:22.144+02:00
2024-09-03 10:10:22.144+02:00
2024-09-03 10:10:22.146+02:00 2024-09-03T08:10:22.145Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-09-03 10:10:22.148+02:00 2024-09-03T08:10:22.148Z [INFO] provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.32.0/linux_amd64/terraform-provider-kubernetes_v2.32.0_x5 id=97
2024-09-03 10:10:22.148+02:00 2024-09-03T08:10:22.148Z [DEBUG] provider: plugin exited
=== ✘ Detecting persistent resources [5034ms]
==> ⧗ Cleaning Up
=== ✘ Cleaning Up [30ms]
=== ✘ Cleaning Up [118ms]
Encountered an error running "coder create", see "coder create --help" for more information
error: prepare build: dry-run workspace: run dry-run provision job: terraform plan: exit status 1
FAIL
2024-09-03 10:10:22.139+02:00 coder_app.code-server: Plan to create
2024-09-03 10:10:22.140+02:00 Plan: 2 to add, 0 to change, 0 to destroy.
2024-09-03 10:10:22.144+02:00 Error: metadata.0.name a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
2024-09-03 10:10:22.144+02:00 on main.tf line 132, in resource "kubernetes_persistent_volume_claim" "home":
2024-09-03 10:10:22.144+02:00 132: name = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}-home"
2024-09-03 10:10:22.144+02:00
2024-09-03 10:10:22.144+02:00
2024-09-03 10:10:22.146+02:00 2024-09-03T08:10:22.145Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-09-03 10:10:22.148+02:00 2024-09-03T08:10:22.148Z [INFO] provider: plugin process exited: plugin=.terraform/providers/registry.terraform.io/hashicorp/kubernetes/2.32.0/linux_amd64/terraform-provider-kubernetes_v2.32.0_x5 id=97
2024-09-03 10:10:22.148+02:00 2024-09-03T08:10:22.148Z [DEBUG] provider: plugin exited
=== ✘ Detecting persistent resources [5034ms]
==> ⧗ Cleaning Up
=== ✘ Cleaning Up [30ms]
=== ✘ Cleaning Up [118ms]
Encountered an error running "coder create", see "coder create --help" for more information
error: prepare build: dry-run workspace: run dry-run provision job: terraform plan: exit status 1
FAIL
Of course, no error of that kind when using the web UI. So I modified the variable kubernetes_persistent_volume_claim with a hardcoded value (juste for a single test, I got the idea of variable resource name) And then the error was now on kubernetes_deployment. In both cases, the value is
name = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}"
name = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}"
It may explain why it works in your case. But I don't get why it works from the web UI and not the CLI. Did I provide enough information? Do you have a clue? I guess we are in different timezones (and it's ok) so I try different things and I watch a lot the logs. I noticed this warning :
2024-09-03 09:30:58.479 [debu] coderd.inmem-provisionerd-coder-77474f649d-6c2f5-0: job log job_id=4cd9b57f-9522-43b1-9b7b-65777274a410 stage="Detecting persistent resources" output="2024-09-03T09:30:58.395Z [WARN] Provider \"registry.terraform.io/coder/coder\" produced an invalid plan for coder_app.code-server, but we are tolerating it because it is using the legacy plugin SDK."
2024-09-03 09:30:58.479 [debu] coderd.inmem-provisionerd-coder-77474f649d-6c2f5-0: job log job_id=4cd9b57f-9522-43b1-9b7b-65777274a410 stage="Detecting persistent resources" output="2024-09-03T09:30:58.395Z [WARN] Provider \"registry.terraform.io/coder/coder\" produced an invalid plan for coder_app.code-server, but we are tolerating it because it is using the legacy plugin SDK."
As I installed and upgraded everything by the rules, even re-creating my template to have all starters up to date, I was not expecting that
Phorcys
Phorcys4mo ago
Thanks for the details, I am familiar with OVHCloud but do not have an account there. For the timezone, I suppose you're in France ? first of all, it seems that our example template is not up-to-date because data.coder_workspace_owner.me is deprecated I will update the example and send it to you in a bit
TitiMoby
TitiMobyOP4mo ago
you have 14h 😉
Phorcys
Phorcys4mo ago
just fyi, I'm French and live in France but I'm part-time at Coder and only get to work outside of usual work hours ;-) which works for most of US, but not great for France! yeah you can probably ignore this one
TitiMoby
TitiMobyOP4mo ago
When I upgrade Coder, do I also upgrade the starter templates?
Phorcys
Phorcys4mo ago
well, sometimes yes but the templates mostly change when the Terraform provider does, and it does not change a lot / allows for most deprecated stuff for a while generally just update the templates when they show a deprecation notice but in this case it does show a notice and the template wasn't updated (cc: @Atif we could probably setup some CI tests to avoid keeping deprecated templates around) just a quick question what's the name of your workspace? workshop_ia?
TitiMoby
TitiMobyOP4mo ago
yep, correct
Phorcys
Phorcys4mo ago
welp
TitiMoby
TitiMobyOP4mo ago
oh... _ is invalid ?
Phorcys
Phorcys4mo ago
I think this might be the stupidest thing ever yes
Phorcys
Phorcys4mo ago
it seems like the CLI let you create something you shouldn't have been able to create
No description
Phorcys
Phorcys4mo ago
PS C:\Users\Phorcys> coder create admin/workshop_ia -t kubernetes-titimoby
version mismatch: client v2.11.2+d53c94b, server v2.10.2+a11b169
download the server version from: https://github.com/coder/coder/releases/v2.10.2
Planning workspace...
=== ✔ Queued [70ms]
==> ⧗ Running
==> ⧗ Running
=== ✔ Running [36ms]
==> ⧗ Setting up
=== ✔ Setting up [114ms]
==> ⧗ Detecting persistent resources
=== ✔ Detecting persistent resources [6134ms]
==> ⧗ Cleaning Up
=== ✘ Cleaning Up [12ms]
=== ✘ Cleaning Up [31ms]
Encountered an error running "coder create", see "coder create --help" for more information
error: prepare build: dry-run workspace: run dry-run provision job: terraform plan: exit status 1

PS C:\Users\Phorcys> coder create admin/workshop-ia -t kubernetes-titimoby
version mismatch: client v2.11.2+d53c94b, server v2.10.2+a11b169
download the server version from: https://github.com/coder/coder/releases/v2.10.2
Planning workspace...
=== ✔ Queued [64ms]
==> ⧗ Running
==> ⧗ Running
=== ✔ Running [12ms]
==> ⧗ Setting up
=== ✔ Setting up [106ms]
==> ⧗ Detecting persistent resources
=== ✔ Detecting persistent resources [7152ms]
==> ⧗ Cleaning Up
=== ✔ Cleaning Up [93ms]
┌──────────────────────────────────────────────────────────────────────┐
│ Workspace Preview │
├──────────────────────────────────────────────────────────────────────┤
│ RESOURCE ACCESS │
├──────────────────────────────────────────────────────────────────────┤
│ kubernetes_deployment.main │
│ └─ main (linux, amd64) coder ssh workshop-ia │
├──────────────────────────────────────────────────────────────────────┤
│ kubernetes_persistent_volume_claim.home │
└──────────────────────────────────────────────────────────────────────┘
PS C:\Users\Phorcys> coder create admin/workshop_ia -t kubernetes-titimoby
version mismatch: client v2.11.2+d53c94b, server v2.10.2+a11b169
download the server version from: https://github.com/coder/coder/releases/v2.10.2
Planning workspace...
=== ✔ Queued [70ms]
==> ⧗ Running
==> ⧗ Running
=== ✔ Running [36ms]
==> ⧗ Setting up
=== ✔ Setting up [114ms]
==> ⧗ Detecting persistent resources
=== ✔ Detecting persistent resources [6134ms]
==> ⧗ Cleaning Up
=== ✘ Cleaning Up [12ms]
=== ✘ Cleaning Up [31ms]
Encountered an error running "coder create", see "coder create --help" for more information
error: prepare build: dry-run workspace: run dry-run provision job: terraform plan: exit status 1

PS C:\Users\Phorcys> coder create admin/workshop-ia -t kubernetes-titimoby
version mismatch: client v2.11.2+d53c94b, server v2.10.2+a11b169
download the server version from: https://github.com/coder/coder/releases/v2.10.2
Planning workspace...
=== ✔ Queued [64ms]
==> ⧗ Running
==> ⧗ Running
=== ✔ Running [12ms]
==> ⧗ Setting up
=== ✔ Setting up [106ms]
==> ⧗ Detecting persistent resources
=== ✔ Detecting persistent resources [7152ms]
==> ⧗ Cleaning Up
=== ✔ Cleaning Up [93ms]
┌──────────────────────────────────────────────────────────────────────┐
│ Workspace Preview │
├──────────────────────────────────────────────────────────────────────┤
│ RESOURCE ACCESS │
├──────────────────────────────────────────────────────────────────────┤
│ kubernetes_deployment.main │
│ └─ main (linux, amd64) coder ssh workshop-ia │
├──────────────────────────────────────────────────────────────────────┤
│ kubernetes_persistent_volume_claim.home │
└──────────────────────────────────────────────────────────────────────┘
yes... looks like that was it we really need to fix this! @Thierry Chantier could you test this and let me know if that was the problem?
TitiMoby
TitiMobyOP4mo ago
I will and it will be my first task tomorrow then I will fill a github issue if you don't to have something better in cli 😉
Phorcys
Phorcys4mo ago
don't worry, I'm already writing the issue ;-) really sorry for the inconvenience ;-(
TitiMoby
TitiMobyOP4mo ago
If it was the issue, I'm happy because I will be able to move on other questions 😉
Phorcys
Phorcys4mo ago
it's great if you can move on! but it's still bad to lose this much time on such a simple thing! here is the issue
Phorcys
Phorcys4mo ago
GitHub
CLI: coder create does not check/sanitize workspace name before c...
Discord thread coder create checks for the name after running the terraform plan, which is fine in most cases even though it makes you lose some time. Here is what would usually happen to an user :...
Phorcys
Phorcys4mo ago
ah yeah nevermind the example on GH does seem to be up-to-date, i read it wrong
TitiMoby
TitiMobyOP4mo ago
using Coder is only one of my projects, but I'm glad to be able to accelerate this project
Phorcys
Phorcys4mo ago
let me know if you have any questions -- I'm excited to see what you'll do with it!
TitiMoby
TitiMobyOP4mo ago
I could not wait until tomorrow 😉
No description
TitiMoby
TitiMobyOP4mo ago
now I have to remove the extensive logs I have 🙂
zounce
zounce4mo ago
Fixed :)
TitiMoby
TitiMobyOP4mo ago
Thanks a lot for all the discussion, I will close this topic because I believe it is the way you handle this "help" channel
Phorcys
Phorcys4mo ago
yes, we basically handle it like GH issues easier to track
TitiMoby
TitiMobyOP4mo ago
easier on Discord? it does not feels as good as GitHub to me but hey, who am I? 😉 /close it is not like that 😄
Phorcys
Phorcys4mo ago
yeah agreed there's some stuff we'll change to make it better
Codercord
Codercord4mo ago
@Phorcys closed the thread.

Did you find this page helpful?