You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for running a script on workspace delete #13387
Right now there's support to run scripts on workspace startup and stop, but it would also be nice to run a script when a workspace is deleted.
For example we have workspaces that are persistent VMs, when they are started they install an register an XDR agent. We'd like to run a script to uninstall the agent which also unregisters it when they are deleted. We can run a script to do so when the workspace is stopped, but then we have to reinstall it on start and uninstall it on stop, and that creates a lot of unnecessary churn.
I guess to run a script on delete transition we need an attribute run_on_delete for coder_script. It will only work if the workspace is in running state.
@matifali Yes, run_on_delete and a running workspace are prerequisites. Ideally we would also have #6175 to ensure proper execution of the script.
Having the run_on_delete property gives a nice way for us to surface a warning if a stopped workspace is deleted and there is a run_on_delete script. Then we can suggest starting the workspace first. Whether or not this is a nice UX flow is another question. I can imagine users first stopping their workspaces before issuing delete, only to be asked to start it again.
Alternatively, we could support this via run_on_stop by setting an environment variable CODER_WORKSPACE_STOP_REASON=stop|delete and letting the template author handle it.
We use coder to create namespaces with permissions for devs.
Devs can add resources to that namespace while they are running.
But since there is no hook when the workspace is deleted and the namespace should be deleted we end up trying to delete the namespace but failing due to finalizers being blocked when not tearing down resources in a specific order.
tl;dr A on delete solution would really help my team out. Perhaps being able to spin up a 1 off job so the deployment doesn't have to be running to complete it.
tl;dr A on delete solution would really help my team out. Perhaps being able to spin up a 1 off job so the deployment doesn't have to be running to complete it.
@wSedlacek
You should be able to run a script using local_provisioner and a null_resource and check if data.coder_workspace.me.transition === "delete".
Activity
kylecarbs commentedon May 28, 2024
You can do this via Terraform.
Use a
null_resourceand check ifdata.coder_workspace.me.transition === "delete", then run a script.evilhamsterman commentedon May 29, 2024
Can you run the script in the workspace like the
run_on_stopoption forcoder_script?matifali commentedon Jun 2, 2024
I guess to run a script on delete transition we need an attribute
run_on_deleteforcoder_script. It will only work if the workspace is in running state.@mafredri could have some thoughts here.
mafredri commentedon Jun 4, 2024
@matifali Yes,
run_on_deleteand a running workspace are prerequisites. Ideally we would also have #6175 to ensure proper execution of the script.Having the
run_on_deleteproperty gives a nice way for us to surface a warning if a stopped workspace is deleted and there is arun_on_deletescript. Then we can suggest starting the workspace first. Whether or not this is a nice UX flow is another question. I can imagine users first stopping their workspaces before issuing delete, only to be asked to start it again.Alternatively, we could support this via
run_on_stopby setting an environment variableCODER_WORKSPACE_STOP_REASON=stop|deleteand letting the template author handle it.matifali commentedon Aug 20, 2024
This could also be used to backup workspace contents for compliance/security purposed.
wSedlacek commentedon Oct 9, 2024
We use coder to create namespaces with permissions for devs.
Devs can add resources to that namespace while they are running.
But since there is no hook when the workspace is deleted and the namespace should be deleted we end up trying to delete the namespace but failing due to finalizers being blocked when not tearing down resources in a specific order.
tl;dr A on delete solution would really help my team out. Perhaps being able to spin up a 1 off job so the deployment doesn't have to be running to complete it.
matifali commentedon Feb 11, 2025
@wSedlacek
You should be able to run a script using
local_provisionerand anull_resourceand check ifdata.coder_workspace.me.transition === "delete".