Repository navigation
Description
Originally posted by @ewengillies in #10352
Problem
coder_script resources run concurrently. There is no Terraform-level way to declare execution ordering between scripts or modules. The current workaround (coder exp sync) requires manually instrumenting every bash script with signaling boilerplate and is experimental.
This causes race conditions, failed startups, and makes composable modules unreliable.
Use cases
UC1 — Sequential scripts within a template
A template has scripts that must run in order: configure SSH keys → clone repo → install dependencies. Today these race.
UC2 — Script depends on a module completing
A template-level script (e.g. "run AI agent on repo") needs all scripts from the git-clone module to finish first. The template author should not need to know the module's internal script names.
UC3 — Module depends on another module
The claude-code module depends on the git-clone module. All scripts in claude-code should wait for all scripts in git-clone to complete. This must work without either module author hardcoding the other's internals.
UC4 — "Run before everything" (inverse dependency)
A script that configures apt mirrors must run before any other script installs packages — including scripts inside third-party modules. Today there is no way to express "run me first" without modifying every downstream script.
UC5 — Resource contention (dpkg/apt lock)
Multiple scripts that use apt-get fail with lock conflicts when run concurrently. Ordering or mutual exclusion must be expressible to prevent this.
UC6 — AI agent multi-step workflow
A user needs this exact sequence, reliably:
- Bootstrap user config (SSH keys, git config)
- Clone repo (requires 1)
- Run coding agent on cloned repo (requires 2)
- Push changes (requires 1-3)
All of these currently run in parallel, regularly failing. (Ref: comment)
UC7 — Preserve parallelism for independent scripts
Scripts with no ordering relationship must continue to run concurrently. Ordering is opt-in and should not regress startup times.
UC8 — Clear failure propagation
If a script fails, dependent scripts should be skipped with a clear error indicating which upstream dependency failed.
Constraints
- The solution must work across modules from the Coder registry without requiring module consumers to know internal script names.
- Module authors must be able to expose ordering interfaces for their scripts.
- The mechanism should be declarative in Terraform, not require bash-level instrumentation.
- An RFC is likely warranted given the public API surface and complexity. See prior discussion on trade-offs between
order,run_after,depends_on, and CLI-based signaling in #10352.
References
- feat: allow execution ordering for
coder_script#10352 — original issue and extensive design discussion - feat: allow execution ordering of coder modules registry#82 — module-level ordering
- https://coder.com/docs/admin/templates/startup-coordination/ — current
coder exp syncdocs - Agent as init system — @spikecurtis on learning from prior art
- Inverse dependency gap — @mafredri on the need to run before other scripts
Activity
matifali commentedon Nov 5, 2026
Declarative script ordering shipped in Coder v2.39.0 with terraform-provider-coder v2.20.0.
Docs: https://coder.com/docs/admin/templates/extending-templates/script-ordering
Reference: https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/script_order
module.<name>) without knowing a module's internal script names or changing its source.requires = "completion"for scripts that should run anyway.phase = "stop".Requires provider v2.20.0+ and Coder v2.39.0+. Older components ignore the rules and run scripts concurrently.
coder exp syncis still available, and the docs include a migration guide.Closing as complete. Please open a new issue for any gaps.