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
feat: allow execution ordering for coder_script #10352
Currently, when building a workspace with multiple instances of coder_script, all are run concurrently, preventing any sequencing logic. To remedy this, some serialization should be implemented allowing users to either define the sequence manually or through a dependency graph.
Reacted by Atif Ali, djarbz, Kevin Conley (Inactive), gjhenrique-prezi, Michael Brewer, Ethan Wolinsky, Thomas Gibson-Robinson, Ben Potter, Phorcys 🐾, phachey-aurorasolar and 4 more
I'd actually call this a bug. We don't know a priori that scripts are safe to run concurrently. In particular, I use dotfiles to install software on startup, and this fails if other scripts are also doing dpkg stuff
Running install.sh...
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 176 (apt-get)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
sudo: add-apt-repository: command not found
Reacted by Stephen Kirby, Atif Ali, phachey-aurorasolar and Clinton Blackburn
I am not sure if we can also use the built-in terraform depends_on as the scripts are run after the terraform apply has finished (in a running workspace by the coder_agent)
I think it'd be neat if depends_on could be used for this because otherwise I think the run_after or order approaches would require Coder (Terraform) modules providing coder_script's to expose those fields as module input variables for consumers of the module to set them, and I imagine that exposing may not be done consistently (at least for 3rd party modules).
We had a chat with @kylecarbs on this yesterday. Here are some conclusions.
depends_on is very idiomatic but may be difficult for module 1 to wait on a script for module 2. We're not entirely sure so this should require a bit of investigation
Another idea is for a startup script to do something inline to wait on another script
This was @bpmct and @kylecarbs preference because it also allows us to do stuff like coder script follow to see logs or even coder script restart if something fails. A pretty good new abstraction :)
This is getting complex enough that we should have an RFC, IMO. But, since I'm thinking about it right now, I'll add some comments directly to the issue.
depends_on sort of makes sense if you squint, but usually it's for telling Terraform about dependencies such that terraform apply does things in the right order. Here, it's not terraform apply that needs to get stuff in the right order, it's the script execution in the agent.
One big downside of coder script wait is that the script itself needs to be aware of the exact thing it is waiting for. But, when scripts are encapsulated in modules, the module author might not know about a problem. For example, my dotfiles consistently fail to run install.sh because another script is holding the dpkg lock. In order to use coder script wait, firstly, it would mean my dotfiles only work on Coder, and secondly, they would probably only work on a specific Coder template where I can figure out what script is conflicting.
Another related issue is that a module author might know what it is dependent on, but not which module provides it. Some dependencies might not be provided by any modules and instead are baked in. For example, my module might require curl. Maybe curl is just available in my image, or maybe some other script or module installs it, as a module author I shouldn't have to know as this creates inflexible dependencies.
Therefore, I think we need to be able to define module dependencies in the template, so that the template author has flexibility to control dependencies, rather than forcing the module author to.
One last comment is that modules generally don't expose their scripts as outputs, so we need to handle all combinations of module and script dependencies. Then, in the terraform provisioner, we can resolve the DAG of scripts & modules into a DAG of just scripts.
script -> script
script -> module
the script gets an edge to every script in the target module
module -> script
every script in the module gets an edge to the target script
module -> module
every script in the module gets an edge to every script in the target module
I agree with @spikecurtis reservation and on having an RFC on this.
My thoughts:
Modules can or cannot contain coder_script resources depending on the nature of what the module does. We have modules that only add some coder_parameter data items to the workspace form.
For Modules that use coder_script, they can have multiple coder_script resources, and in that case, we do need an order property that the module builder will use or if someone is directly using coder_script resources in a template.
For all modules that use any coder_script resource, we must pass an agent_id in the form of coder_agent.NAME.id as input. So, for one module to depend on another, we need a way to let the agent running the module's coder_script resources wait for any dependency modules' ' coder_script` resources to finish executing. I am unsure how it can be done while staying close to what we have now.
For those looking for this behavior today, you can use a bash while loop in your coder script to wait for a specific command (e.g. code-server to become available or conditionals to wait for a process to complete, start, or be unlocked)
For those looking for this behavior today, you can use a bash while loop in your coder script to wait for a specific command (e.g. code-server to become available or conditionals to wait for a process to complete, start, or be unlocked)
This kind of works, but there are many other cases, like git-clone script needs to complete before executing the next script from another module.
We are using more than 16 scripts at startup. Some of them has to wait until git cloned has finished. Other has to wait for other scripts or at least part of it. We are providing 2 simple bash scripts to realize the sendSignal and waitFor. This creates a file under /tmp and the other waits in a while loop until it is created. This way we can build our own DAG.
NOTE: Sending signals should be possible at any time or any place. Not just at the edges of entry and exit points!
This works pretty stable. But it would be nice if there was something similar as build in function without needing to store files in a temporary filesystem. For me I could think of storing signals at workspace level.
coder signal git-cloned # This sends the signal to coder server
coder waitfor git-cloned # wait until signal "git-clond" has been send to coder server
Is that the intended approach for testing right now ?
Or is there (or will there be) a first-class Terraform attribute for declaring dependencies directly in coder_script?
Feature flags / version requirements
Do we need to enable any experimental flags to use this?
Is there a minimum Coder server / agent version required?
Does the Terraform provider need to be on a specific version?
It would be helpful to understand:
Whether this is purely runtime orchestration (CLI-only inside scripts), or
If we should expect upcoming Terraform-level support for defining dependencies declaratively.
I'm delighted to see your interest in the feature.
We do have plans to integrate this with Terraform for a better user experience and to allow a-priori dependency expression. The coder exp sync want was the minimal shippable increment.
The implementation isn't planned for the immediate term, but I do have some conceptual designs ready for this.
I hope to implement this as soon as I can, but I can't provide a more specific timeline than that right now. If anything changes, I'll post an update here.
In the meantime, My understanding is that for now we could invoke these cli commands inside a coder_script, for example at the beginning of the script: coder exp sync want --script="<dependency-script>", Is this expectation correct, for testing and early adoption right now.
There is currently no first-class Terraform attribute for declaring dependencies directly in coder_script, but that is something you’re conceptually planning for later — correct?
Appreciate the guidance — we’re keen to start experimenting with this.
Correct, you can find more information on how to do so here.
Correct.
I'm excited that you're experimenting with this!
If you'd like to have a more high-bandwidth conversation, please feel free to reach out in our community Discord as well. I'd be happy to take note of your experience onboarding the feature. It will help me build it out to be maximally valuable!
just to add a request/use-case. It goes like this:
Sometimes I want my coder_script to depend on a TF module.
The implementation details of the TF module are outside my scope/control.
a. The TF module might call coder_script or something else entirely.
b. A common issue would be something like apt-get or some other blocking installation calls inside the module.
c. I don't control how the module behaviour changes over time either - its internals are opaque.
The script is in my control - i.e. I can add coder cli calls at my whim.
I want to run my script after one or more modules-I-install-but-cannot-change have finished.
Is this something that is on the table if/when the first-class TF attribute is ready (a la depends_on)? Are there any workarounds here that do not involve sleep?
Also - is there a better issue to raise this use-case on? this current one is closed, which makes sense since the original scope only mentioned coder_script dependencies.
I've built a prototype to add Terraform support for the ordering solution we've built so far and I'd love some feedback from any interested stakeholders. The solutions proposed so far all rely on a decentralised dependency definition mechanism. See here for examples. This is similar to how Systemd declares dependencies within its unit files. Unfortunately, these do not stand up to implementation in our particular environment because of Terraform SDK related minutiae.
It uses a centrally declared dependency graph. Given this solution, any template author would be able to centrally manage the ordering and dependencies of any coder script in their template, regardless of the module of origin. Directed Acyclic Dependency graphs of practically arbitrary complexity should be possible, although more complex graphs will be difficult to troubleshoot unless we build additional tooling to assist.
If using this interface, users would not need to use the coder exp sync commands.
Thank you @SasSwart for this, I'll try out in couple of weeks. this will be very handy, compared to coder exp sync commands
I was just curious on the API, can we not use depends_on parameter to build the DAG, given it's terraform native way to declare dependencies, API might be more intuative, if that's feasible. I'm not sure of any complications to use that, or if it wouldn't fit certain usecases. But I'm just curious on API
Ignore this : I've read the above thread, which is very detailed, Thankyou
Activity
spikecurtis commentedon Oct 30, 2023
I'd actually call this a bug. We don't know a priori that scripts are safe to run concurrently. In particular, I use dotfiles to install software on startup, and this fails if other scripts are also doing dpkg stuff
matifali commentedon Oct 30, 2023
It could be done in multiple ways,
run_after = coder_script.dotfiles. If norun_afterexists, we can default to running alphabetically.orderthe same as withcoder_parameter, It may look something like the below,depends_onas the scripts are run after the terraform apply has finished (in a running workspace by thecoder_agent)I am not very sure how we can expose this on module level and how the
coder_agentwill use this.kconley-sq commentedon Oct 30, 2023
I think it'd be neat if
depends_oncould be used for this because otherwise I think therun_afterororderapproaches would require Coder (Terraform) modules providingcoder_script's to expose those fields as module input variables for consumers of the module to set them, and I imagine that exposing may not be done consistently (at least for 3rd party modules).ammario commentedon Nov 13, 2023
I strongly prefer a
depends_onor similar DAG-based approach as its consistent with Terraform's philosophy.matifali commentedon Nov 14, 2023
This is a prerequisite for coder/registry#82
bpmct commentedon Nov 16, 2023
We had a chat with @kylecarbs on this yesterday. Here are some conclusions.
coder script wait code-server code-server --install-extension myextensioncoder script followto see logs or evencoder script restartif something fails. A pretty good new abstraction :)orderpropertyspikecurtis commentedon Nov 16, 2023
This is getting complex enough that we should have an RFC, IMO. But, since I'm thinking about it right now, I'll add some comments directly to the issue.
depends_onsort of makes sense if you squint, but usually it's for telling Terraform about dependencies such thatterraform applydoes things in the right order. Here, it's notterraform applythat needs to get stuff in the right order, it's the script execution in the agent.One big downside of
coder script waitis that the script itself needs to be aware of the exact thing it is waiting for. But, when scripts are encapsulated in modules, the module author might not know about a problem. For example, my dotfiles consistently fail to runinstall.shbecause another script is holding the dpkg lock. In order to usecoder script wait, firstly, it would mean my dotfiles only work on Coder, and secondly, they would probably only work on a specific Coder template where I can figure out what script is conflicting.Another related issue is that a module author might know what it is dependent on, but not which module provides it. Some dependencies might not be provided by any modules and instead are baked in. For example, my module might require
curl. Maybecurlis just available in my image, or maybe some other script or module installs it, as a module author I shouldn't have to know as this creates inflexible dependencies.Therefore, I think we need to be able to define module dependencies in the template, so that the template author has flexibility to control dependencies, rather than forcing the module author to.
One last comment is that modules generally don't expose their scripts as outputs, so we need to handle all combinations of module and script dependencies. Then, in the terraform provisioner, we can resolve the DAG of scripts & modules into a DAG of just scripts.
matifali commentedon Nov 16, 2023
I agree with @spikecurtis reservation and on having an RFC on this.
My thoughts:
coder_scriptresources depending on the nature of what the module does. We have modules that only add somecoder_parameterdata items to the workspace form.coder_script, they can have multiplecoder_scriptresources, and in that case, we do need an order property that the module builder will use or if someone is directly usingcoder_scriptresources in a template.coder_scriptresource, we must pass anagent_idin the form ofcoder_agent.NAME.idas input. So, for one module to depend on another, we need a way to let the agent running the module'scoder_scriptresources wait for any dependency modules' ' coder_script` resources to finish executing. I am unsure how it can be done while staying close to what we have now.bpmct commentedon Nov 18, 2023
Workaround
For those looking for this behavior today, you can use a bash
whileloop in your coder script to wait for a specific command (e.g.code-serverto become available or conditionals to wait for a process to complete, start, or be unlocked)michaelbrewer commentedon Apr 5, 2024
This kind of works, but there are many other cases, like
git-clonescript needs to complete before executing the next script from another module.MrPeacockNLB commentedon Apr 5, 2024
We are using more than 16 scripts at startup. Some of them has to wait until git cloned has finished. Other has to wait for other scripts or at least part of it. We are providing 2 simple bash scripts to realize the sendSignal and waitFor. This creates a file under /tmp and the other waits in a while loop until it is created. This way we can build our own DAG.
NOTE: Sending signals should be possible at any time or any place. Not just at the edges of entry and exit points!
This works pretty stable. But it would be nice if there was something similar as build in function without needing to store files in a temporary filesystem. For me I could think of storing signals at workspace level.
@michaelbrewer I can say this works as expected
41 remaining items
SasSwart commentedon Oct 20, 2025
Update:
The first of a few components required for this feature is nearing completion here:
#20208
feat: implement agent socket api, client and cli (coder#20758)
feat: implement agent socket api, client and cli (#20758)
SasSwart commentedon Dec 1, 2025
Hey all,
Update:
We've implemented an experimental feature to address this issue. We're trying to get it in by the next release (cc @david-fraley).
I will provide documentation on how to use the feature soon, but basic examples can already be seen in the description of #20976.
Ashok-Varma commentedon Feb 19, 2026
Hi @SasSwart 👋
This is great progress — thanks for pushing this forward!
I had a couple of clarifications regarding usage:
Can we use this with existing Terraform-based templates?
The examples in feat: implement agent socket api, client and cli (#20758) #20976 show usage via CLI commands inside scripts, but I don’t see documentation yet on how this integrates from a Terraform perspective. feat: allow execution ordering for
coder_script#10352 (comment) which would be last phase of this. But just curiousTerraform usage pattern
My understanding is that we would invoke this inside a
coder_script, for example at the beginning of the script:coder exp sync want --script="<dependency-script>"Is that the intended approach for testing right now ?
Or is there (or will there be) a first-class Terraform attribute for declaring dependencies directly in
coder_script?Feature flags / version requirements
It would be helpful to understand:
Thanks again — excited to try this out 🚀
SasSwart commentedon Feb 19, 2026
Hey there @Ashok-Varma!
I'm delighted to see your interest in the feature.
We do have plans to integrate this with Terraform for a better user experience and to allow a-priori dependency expression. The
coder exp sync wantwas the minimal shippable increment.The implementation isn't planned for the immediate term, but I do have some conceptual designs ready for this.
I hope to implement this as soon as I can, but I can't provide a more specific timeline than that right now. If anything changes, I'll post an update here.
Ashok-Varma commentedon Feb 20, 2026
Thank you for the clarification @SasSwart 🙌
Just confirming these 2 points
coder_script, for example at the beginning of the script:coder exp sync want --script="<dependency-script>", Is this expectation correct, for testing and early adoption right now.coder_script, but that is something you’re conceptually planning for later — correct?Appreciate the guidance — we’re keen to start experimenting with this.
SasSwart commentedon Feb 20, 2026
I'm excited that you're experimenting with this!
If you'd like to have a more high-bandwidth conversation, please feel free to reach out in our community Discord as well. I'd be happy to take note of your experience onboarding the feature. It will help me build it out to be maximally valuable!
ewengillies commentedon Feb 27, 2026
thanks for shipping an exciting new feature!
just to add a request/use-case. It goes like this:
coder_scriptto depend on a TFmodule.a. The TF module might call
coder_scriptor something else entirely.b. A common issue would be something like
apt-getor some other blocking installation calls inside the module.c. I don't control how the module behaviour changes over time either - its internals are opaque.
codercli calls at my whim.Is this something that is on the table if/when the first-class TF attribute is ready (a la
depends_on)? Are there any workarounds here that do not involvesleep?Also - is there a better issue to raise this use-case on? this current one is closed, which makes sense since the original scope only mentioned
coder_scriptdependencies.matifali commentedon Feb 27, 2026
@ewengillies, I created #22365 to cover the Terraform side of this.
@SasSwart please update/edit the issue as needed.
SasSwart commentedon Mar 3, 2026
Update:
I've built a prototype to add Terraform support for the ordering solution we've built so far and I'd love some feedback from any interested stakeholders. The solutions proposed so far all rely on a decentralised dependency definition mechanism. See here for examples. This is similar to how Systemd declares dependencies within its unit files. Unfortunately, these do not stand up to implementation in our particular environment because of Terraform SDK related minutiae.
Instead, I've implemented this interface:
It produces the following timing chart:

It uses a centrally declared dependency graph. Given this solution, any template author would be able to centrally manage the ordering and dependencies of any coder script in their template, regardless of the module of origin. Directed Acyclic Dependency graphs of practically arbitrary complexity should be possible, although more complex graphs will be difficult to troubleshoot unless we build additional tooling to assist.
If using this interface, users would not need to use the
coder exp synccommands.Ashok-Varma commentedon Mar 7, 2026
Thank you @SasSwart for this, I'll try out in couple of weeks. this will be very handy, compared to
coder exp synccommandsI was just curious on the API, can we not usedepends_onparameter to build the DAG, given it's terraform native way to declare dependencies, API might be more intuative, if that's feasible.I'm not sure of any complications to use that, or if it wouldn't fit certain usecases. But I'm just curious on APIIgnore this : I've read the above thread, which is very detailed, Thankyou
Ashok-Varma commentedon Apr 3, 2026
Looks like we don't have this in Terra-form yet
matifali commentedon Apr 3, 2026
Yes for tracking that you can follow #22365