Issue with starting workspaces that were running for months.

Hello, today, my templates stopped working after months of being used. Do you have any idea what is going on and how to fix it? Here is the error log: https://paste.brcb.eu/ybejasaqut.yaml And here is my main.tf: https://paste.brcb.eu/buhubymaxo.sh
18 Replies
Codercord
Codercord3w ago
<#1313784155561000961>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Phorcys
Phorcys3w ago
@Šimon DJ Čecháček in the v2 of the provider, coder_workspace.me.owner_* variables have been removed in favor of the new coder_workspace_owner data source please see https://registry.terraform.io/providers/coder/coder/latest/docs/guides/version-2-upgrade#data-source-coder_workspace for instructions
Šimon DJ Čecháček
I will check it
Phorcys
Phorcys3w ago
basically just add data "coder_workspace_owner" "me" {} next to the data "coder_workspace" "me" {} definition you already have in your template and replace calls to deprecated values
Šimon DJ Čecháček
Okay, Will try 😄 Can I ask for help if I fail? 😄
Phorcys
Phorcys3w ago
of course!
Šimon DJ Čecháček
I hope I updted it correctly, but now I end on Error: Failed to install provider Error while installing kreuzwerker/docker v3.0.2: unsuccessful request to https://github.com/kreuzwerker/terraform-provider-docker/releases/download/v3.0.2/terraform-provider-docker_3.0.2_linux_amd64.zip: 504 Gateway Timeout Maybe I got banned for too many attemps 😄 In the meaintime Here is how I updated it: 94: username = data.coder_workspace_owner.me.name 95: weburl = "https://preview--main--${lower(data.coder_workspace_owner.me.name)}--${data.coder_workspace.me.owner}.coder.domain.tld" 544: labels { label = "coder.owner" value = data.coder_workspace_owner.me.name 548: labels { label = "coder.owner_id" value = data.coder_workspace_owner.me.id } Is tha correct? 😄 Okay, this is wrong: weburl = "https://preview--main--${lower(data.coder_workspace.me.name)}--${data.coder_workspace.me.owner}.coder.artdev.space" visibility_switch = data.coder_parameter.visibility.value == "false" ? "authenticated" : "public" Can you help me fix this line please?
Phorcys
Phorcys3w ago
replace data.coder_workspace.me.owner with data.coder_workspace_owner.me.name otherwise looks good!
Šimon DJ Čecháček
Great! This is hopefully the last one I am fighting with:
Error: Unsupported attribute
on .terraform/modules/coder-login/main.tf line 22, in resource "coder_script" "coder-login":

22: CODER_USER_TOKEN : data.coder_workspace.me.owner_session_token,
This object has no argument, nested block, or exported attribute named "owner_session_token".
Error: Unsupported attribute
on .terraform/modules/coder-login/main.tf line 22, in resource "coder_script" "coder-login":

22: CODER_USER_TOKEN : data.coder_workspace.me.owner_session_token,
This object has no argument, nested block, or exported attribute named "owner_session_token".
This is the current value: env = ["CODER_AGENT_TOKEN=${data.coder_workspace_owner.me.session_token}"] This is the original value: env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"] Any idea what is wrong?
Phorcys
Phorcys3w ago
oh no the agent token is correct you only have to replace stuff that starts with data.coder_workspace_owner so, coder_agent.main.token is what you want
Šimon DJ Čecháček
Okay, I understand that. But with what should be data.coder_workspace.me.name replaced? I am unable to understand it from the guide on terraform site you sent, I am sorry. maybe data.coder_workspace_owner.me.full_name? Well, that is not correct as it ends on Error: Unable to create container: Error response from daemon: Invalid container name (coder-radekchaloupka-radek chaloupka), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed on main.tf line 579, in resource "docker_container" "workspace": 579: resource "docker_container" "workspace" { Well, I remembered I created the template from a docker starter template, so I went there and copied the same stuff to update the variables, now I can build a template, but my startscript fails on permissions:
fatal: could not create work tree dir '/home/simonc/coderconfig': Permission denied
/bin/bash: line 22: cd: /home/simonc/coderconfig: No such file or directory
CONFIG REPO CLONE FAILED
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
Repository has been updated, and local changes have been ignored.
ln: failed to create symbolic link '/home/simonc/configs': Permission denied
project-base-codered
ln: failed to create symbolic link '/home/simonc/repo': Permission denied
fatal: could not create work tree dir '/home/simonc/coderconfig': Permission denied
/bin/bash: line 22: cd: /home/simonc/coderconfig: No such file or directory
CONFIG REPO CLONE FAILED
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
Repository has been updated, and local changes have been ignored.
ln: failed to create symbolic link '/home/simonc/configs': Permission denied
project-base-codered
ln: failed to create symbolic link '/home/simonc/repo': Permission denied
That code worked for months, so I am afraid is something to do witht the recent change, is there anything that changed permissions in coder workspace? I think its because the coder command are no more running under the users username, but under coder username? Yes, I ran the whole coder and startuo script under the individual user (owner of the workspace), now it runs under user coder and it makes issues as coder does not own the folder. I do not want to change the user structure asd that would break exisiting machines Okay, for now I forced the older version of resource so our devs can work. I am unable to make it work :/
Atif
Atif3w ago
Hi @Šimon DJ Čecháček We recommned always pinning provider versions in prodiction.
Atif
Atif3w ago
It should help you migrate without a issue. IF you see any isssues, please let us know and we will update the guide.
Šimon DJ Čecháček
Yeah i just learned that. I read the tutorial and was able to build it. But my issue is now my user will not even create and everything runs under user coder, so folders cant be accessed and etc. There is no word about this in the guide
Phorcys
Phorcys2w ago
that is not something that should happen yeah okay I would encourage you to start over with your existing template and redo the replacing so basically this guide says: - data.coder_workspace.me.owner_id -> data.coder_workspace_owner.me.id - data.coder_workspace.me.owner -> data.coder_workspace_owner.me.name - data.coder_workspace.me.owner_name -> data.coder_workspace_owner.me.full_name - data.coder_workspace.me.owner_email -> data.coder_workspace_owner.me.email - data.coder_workspace.me.owner_groups -> data.coder_workspace_owner.me.groups - data.coder_workspace.me.owner_oidc_access_token -> data.coder_workspace_owner.me.oidc_access_token - data.coder_workspace.me.owner_session_token-> data.coder_workspace_owner.me.session_token all you should need to do is find and replace for these hey @Šimon DJ Čecháček, any luck?
Šimon DJ Čecháček
Hi there. My Uni finals started, so I wan unable to test it. Will do ASAP and let you know
Phorcys
Phorcys7d ago
sounds good!

Did you find this page helpful?