Files
coder/docs/templates/extending-templates/script-ordering.md
T
coder[bot]andNick Vigilante a988af518c docs: rename the user-guides folder to workspaces (#31650)
> [!NOTE]
> Generated by Coder Agents. The branch and this description were
written by an AI agent and need human review.

## Summary

Fourth stacked PR for the docs IA overhaul. PR C renamed the User guides
sidebar section to **Workspaces**. This PR renames its folder to match,
so the folder tree and the sidebar agree (DOCS-1154). The section's
title, position, and contents don't change.

- `docs/user-guides/**` moves to `docs/workspaces/**` with `git mv`: 33
files. That includes pages that are not in the sidebar and the three
pages PR C moved in (`persistent-shared-workspaces.md`,
`cloning-git-repositories.md`, `speed-up-templates.md`).
- `docs/manifest/user-guides.yml` and `docs/manifest/user-guides/` (4
files) move to `docs/manifest/workspaces.yml` and
`docs/manifest/workspaces/`, and `index.yml` lists `workspaces.yml` in
the same position.
- Every relative link and image path is fixed, in moved pages and in
pages that link to them. This was done in one scripted pass from a clean
tree. `docs/images/` stays where it is, so images under
`docs/images/user-guides/` keep their names; only the relative paths
that point at them change.
- Commit 2, `chore: point in-product docs links at the new docs paths`,
updates docs URLs outside `docs/`, then regenerates the files built from
them with `make gen`. You can drop that commit; the redirects cover the
old URLs.
- Updated sources: `site/` `docs()` links and hardcoded docs URLs,
`cli/sharing.go` help text, `README.md`, `examples/templates/` READMEs
and `docker/main.tf`, templatebuilder base READMEs, and the doc-check
skill's audience persona.
- Regenerated files: the `coder sharing add/remove` CLI golden files,
`docs/reference/cli/sharing/{add,remove}.md`, and
`examples/examples.gen.json`.
- Commit 3, `fix: keep docs links healthy before the release`, keeps
links working on the live site until a release that includes this stack
becomes the default docs version:
- In hand-written pages, the docs commit's rewrite left 4 absolute
`https://coder.com/docs/workspaces/...` URLs. They are now relative
links, anchors kept: `admin/networking/wildcard-access-url.md`,
`install/operate/upgrade/esr-2.24-2.29-upgrade.md` (2 links), and
`workspaces/workspace-access/jetbrains/gateway.md`.
- Every hardcoded, unversioned `https://coder.com/docs/workspaces/...`
URL that commit 2 introduced outside `docs/` goes back to
`https://coder.com/docs/user-guides/...`. That covers 32 URLs in
`README.md`, `cli/sharing.go`, the examples and templatebuilder READMEs,
`examples/templates/docker/main.tf`, the `UserDropdownContent.tsx`
constant and its story assertion, and a JSDoc link in
`site/src/api/queries/workspaces.ts`. `make gen` then regenerated the
CLI golden files, `docs/reference/cli/sharing/{add,remove}.md`, and
`examples/examples.gen.json`. See "Post-release follow-up".
- The `site/` `docs()` changes stay, because those URLs are versioned
(`/docs/@vX.Y.Z/...`) and resolve once the release ships.

Stack: `docs/ia-ai-sections` (#31645, with Templates squash-merged in
#31646) → `docs/ia-tutorials-nav` (#31647) → **this PR**.

Refs: Linear DOCS-1154, DOCS-1179.

## Move map

| Old | New |
| --- | --- |
| `docs/user-guides/**` (33 files) | `docs/workspaces/**` |
| `docs/manifest/user-guides.yml` | `docs/manifest/workspaces.yml` |
| `docs/manifest/user-guides/**` (4 files) |
`docs/manifest/workspaces/**` |

## Redirects added

| Source | Destination |
| --- | --- |
| `/docs/user-guides` | `/docs/workspaces` |
| `/docs/user-guides/:path*` | `/docs/workspaces/:path*` |

Updated existing rules so none of them chain through the new wildcard:

| Source | Old destination | New destination |
| --- | --- | --- |
| `/docs/ai-coder/ide-agents` | `/docs/user-guides/workspace-access` |
`/docs/workspaces/workspace-access` |
| `/docs/tutorials/best-practices/speed-up-templates` |
`/docs/user-guides/speed-up-templates` |
`/docs/workspaces/speed-up-templates` |
| `/docs/tutorials/cloning-git-repositories` |
`/docs/user-guides/cloning-git-repositories` |
`/docs/workspaces/cloning-git-repositories` |
| `/docs/tutorials/persistent-shared-workspaces` |
`/docs/user-guides/persistent-shared-workspaces` |
`/docs/workspaces/persistent-shared-workspaces` |

**coder.com and router static redirects:** a chain simulation of
coder.com's and the router's static rules together with this branch's
`docs/redirects.json` finds one problem from this PR. The static
`/docs/workspaces` → `/docs/user-guides/workspace-management` rule in
both repos would hide the new `docs/workspaces/index.md` behind a
redirect to `/docs/workspaces/workspace-management`.
coder/coder.com#1201 and coder/docs-engine#304 remove it, together with
the Templates loops from #31645, once a release with this layout is the
docs mainline. If this PR ships in a later release than #31645, drop the
`/docs/workspaces` part of those PRs until then. The other static
`/docs/user-guides/...` destinations there still work; each now takes
two redirects.

## Deviations from the proposal

- **Not in Proposal 1.** The proposal only renamed the sidebar title.
This folder rename was requested afterward so the folder-driven renderer
shows the same name.
- **Generated files belong to commit 2.** Commit 1 doesn't edit
generated docs. They change only through their sources and `make gen`.
- **Left unchanged on purpose:**
  - `docs/images/user-guides/` keeps its name, as requested.
- `.github/workflows/test-docs-preview-mapper.sh` uses
`docs/user-guides/...` as synthetic fixture paths.
- `docs/templates/extending-templates/jetbrains-airgapped.md` has a
"file a GitHub issue" link whose URL-encoded body names
`coder.com/docs/user-guides/workspace-access/jetbrains/jetbrains-airgapped`.
That URL was already wrong before this PR (the page lives under
`templates/`), and it only pre-fills an issue body, so I left it.
- Database migrations and notification golden files: none of them
contain `user-guides` links.

## Open questions for Nick

1. Should `docs/images/user-guides/` be renamed to
`docs/images/workspaces/` in a follow-up, or stay as is?
2. Frontend review nits on existing code that this PR only touched; I
didn't change them:
- `UserDropdownContent.tsx` defines `CODER_DESKTOP_DOCS_URL` as a
hardcoded `https://coder.com/docs/...` URL instead of
`docs("/workspaces/desktop")`, which `SSHButton.tsx` uses for the same
page.
- The `UserDropdown` and `SecretsPageView` stories' `play` functions
only assert link attributes.

## Post-release follow-up

After a release that includes this stack becomes the default docs
version on coder.com, point these hardcoded URLs at the new paths. They
work today and redirect after the release. Anchors are unchanged. Rerun
`make gen` afterward to update the CLI golden files,
`docs/reference/cli/sharing/{add,remove}.md`, and
`examples/examples.gen.json`.

| Current (old) URL | Post-release URL | Files |
| --- | --- | --- |
| `https://coder.com/docs/user-guides/desktop` |
`https://coder.com/docs/workspaces/desktop` |
`site/src/modules/dashboard/Navbar/UserDropdown/UserDropdownContent.tsx`,
`UserDropdown.stories.tsx` |
| `https://coder.com/docs/user-guides/devcontainers` |
`https://coder.com/docs/workspaces/devcontainers` | `README.md` |
| `https://coder.com/docs/user-guides/shared-workspaces` |
`https://coder.com/docs/workspaces/shared-workspaces` | `cli/sharing.go`
(CLI help, 2 places) |
| `https://coder.com/docs/user-guides/workspace-access` |
`https://coder.com/docs/workspaces/workspace-access` | `README.md` |
|
`https://coder.com/docs/user-guides/workspace-access/jetbrains/toolbox`
| `https://coder.com/docs/workspaces/workspace-access/jetbrains/toolbox`
| `examples/templates/docker/main.tf` |
| `https://coder.com/docs/user-guides/workspace-dotfiles` |
`https://coder.com/docs/workspaces/workspace-dotfiles` |
`coderd/templatebuilder/bases/{azure-linux,docker,kubernetes}/README.md`,
`examples/templates/{azure-linux,docker,kubernetes}/README.md` |
| `https://coder.com/docs/user-guides/workspace-management` |
`https://coder.com/docs/workspaces/workspace-management` | `README.md`,
`coderd/templatebuilder/bases/{aws-linux,aws-windows,azure-linux,digitalocean-linux,docker,kubernetes}/README.md`,
`examples/templates/{aws-linux,aws-windows,azure-linux,azure-windows,digitalocean-linux,docker-devcontainer,docker-envbuilder,docker,kubernetes-devcontainer,kubernetes,nomad-docker}/README.md`,
`site/src/api/queries/workspaces.ts` (JSDoc) |

## Validation run

- `make gen/docs-manifest`: clean diff afterward.
- `make lint/docs-manifest`, `lint/docs-redirects` (`-base
docs/ia-tutorials-nav`: 36 rules OK), `lint/docs-html`, `lint/emdash`:
pass.
- `pnpm check-docs` (markdownlint + table formatter): pass.
- Vale over `docs/`: identical to `docs/ia-tutorials-nav` (12 warnings,
1 error, 645 suggestions, all pre-existing).
- Local relative-link check over `docs/**/*.md`: 0 unresolved (3410
links and images in 498 files).
- `grep -rn user-guides docs/` finds only `docs/redirects.json`, image
paths under `docs/images/user-guides/`, and the issue link above.
- Pre-commit hook: `make pre-commit-light` on the docs commit, and the
full `make pre-commit` (gen, fmt, lint/go, lint/ts, build, and others)
on the chore commit. `make gen` left a clean tree.
- Targeted tests:
- Go: `go test ./cli -run TestCommandHelp`, `./examples/...`,
`./coderd/templatebuilder/...`.
- Site: Vitest for the touched directories (22 files, 409 tests), and
the `UserDropdown` and `SecretsPageView` story tests (2 files, 59
tests).
- Every `docs()` path and `coder.com/docs` URL in the chore diff
resolves to a page and heading in this branch.
- Frontend deep review (all 8 roles) on the `site/` diff: no blocking or
should-fix findings; the nits are in question 2.
- Restacked on the rebased `docs/ia-tutorials-nav` (on `main` at
`ccf5ec74ae`). After the restack, `make gen/docs-manifest` (clean),
`lint/docs-manifest`, `lint/docs-redirects` (36 rules OK),
`lint/docs-html`, `lint/emdash`, `pnpm check-docs`, and the
relative-link and anchor check over the changed pages pass.
- Page counts: `docs/**/*.md` (excluding `.style`) 485 → 485;
`manifest.json` routes 482 → 482 (moves only).
- **Link health (commit 3):**
- linkspector 0.5.6 with `.github/.linkspector.yml` over all of `docs/`,
like the weekly docs job, run locally.
- `origin/main`: 0 errors. Before the fix (`7382a41faa`): 11 errors. 10
were `https://coder.com/docs/<new path>` 404s: the 6 from #31645 plus 4
`workspaces/...` URLs. The 11th was a transient Red Hat URL failure in
`install/server/openshift.md`, which is unchanged from `main` and passed
on reruns. After the fix (`c1f287fc1b`): 0 errors. Nothing is new
compared with `main`.
- After the fix: `make gen/docs-manifest` (clean), `lint/docs-manifest`,
`lint/docs-redirects` (36 rules OK against `docs/ia-tutorials-nav`),
`lint/docs-html`, `lint/emdash`, `pnpm check-docs`, and the
relative-link check (0 unresolved in 3419 links) pass. The full `make
pre-commit`, including `make gen`, passed on the commit.
- Outside `docs/`, no line in this stack adds an unversioned
`coder.com/docs` URL compared with `main`.
  - Tests after the fix:
- Go: `go test ./cli -run 'TestCommandHelp|TestServerYAMLConfig'`,
`./examples/...`, `./coderd/templatebuilder/...`, `./cli/cliui`.
- Site: Vitest for the touched directories (21 files, 404 tests), and
the `UserDropdown` story tests (28 tests).
- **Skipped:** the docs-engine sync check, which was not available in
this environment.

<details>
<summary>Implementation notes</summary>

- Same one-shot move script as PRs A to C, with a single rule,
`docs/user-guides/` → `docs/workspaces/`. It resolves each relative link
against the page's old directory, maps the target through the move,
recomputes it from the new directory, and also rewrites
`coder.com/docs/...` and
`github.com/coder/coder/(blob|edit|tree)/main/docs/...` URLs. It skips
fenced code blocks and inline code, and refuses to run on a dirty
`docs/` tree.
- After #31645 and #31647 got their link-health fixes, a plain rebase of
this branch conflicted in `esr-2.24-2.29-upgrade.md`, where both changed
the same table rows. Instead of resolving by hand, I rebuilt the docs
and chore commits from the fixed `docs/ia-tutorials-nav` with the same
scripts. The resulting docs commit differs from the earlier one only by
#31645's fix, and the chore commit touches the same 36 files.
- No hand edits were needed in the docs commit. The sidebar sources were
renamed with `git mv` and their `path`/`include` prefixes rewritten.
- The redirect script repointed every existing destination under
`/docs/user-guides` before appending the two new rules.
- Restacked on 2026-11-03 onto `docs/ia-tutorials-nav` at `76aed1a618`.
The chore commit conflicted with #31603 in
`site/src/pages/WorkspacesPage/WorkspaceHelpPopover.tsx`; both links
keep `main`'s `target="_blank" rel="noreferrer"` with only the path
changed, and the `WorkspacesPage` Vitest suite (24 tests) passes. Folded
into the docs commit: the `../user-guides/` links in
`docs/coder-agents/bring-your-own-mcp-servers.md`, a page `main` added,
now point at `../workspaces/`.

</details>

---------

Co-authored-by: coder[bot] <137810501+coder[bot]@users.noreply.github.com>
Co-authored-by: Nick Vigilante <nick.vigilante@coder.com>
2026-11-04 17:41:22 -05:00

18 KiB

title
title
Order startup and shutdown scripts

As a template author, you can use the coder_script_order data source to declare dependencies between startup or shutdown scripts. You can order individual coder_script resources or all scripts in a child module without adding coordination commands to script bodies.

Splitting workspace initialization into separate coder_script resources lets independent tasks run in parallel, which can shorten startup time. Some scripts still depend on work performed by others. For example, a script that installs application dependencies needs the repository to be cloned before it starts. Without declared dependencies, these scripts can run at the same time, causing intermittent startup failures.

Requirements

Script ordering requires compatible versions of every component:

  • The Coder Terraform provider v2.20.0 or later.
  • Coder control plane and provisioners v2.39.0 or later.
  • Workspace agents, including dev container sub-agents, v2.39.0 or later.

Older components can ignore ordering declarations and run scripts concurrently without reporting a compatibility error. Updating the provider alone doesn't enable ordering on older Coder deployments or agents.

Declare dependencies

Add a coder_script_order data source to your template alongside your scripts. For example, clone a Node.js repository before installing its dependencies:

resource "coder_script" "clone" {
  agent_id     = coder_agent.main.id
  display_name = "Clone Repository"
  run_on_start = true
  script       = "test -d ~/app/.git || git clone https://github.com/your-org/your-app.git ~/app"
}

resource "coder_script" "install" {
  agent_id     = coder_agent.main.id
  display_name = "Install Dependencies"
  run_on_start = true
  script       = "cd ~/app && npm ci"
}

data "coder_script_order" "startup" {
  rule {
    run   = ["coder_script.install"]
    after = ["coder_script.clone"]
  }
}

On startup, Install Dependencies waits for Clone Repository to succeed, then installs the packages. The default requirement is success. If cloning fails, Coder skips dependency installation.

Each coder_script_order data source contains one or more rule blocks:

Attribute Required Meaning
run Yes A nonempty list of selectors for scripts that wait.
after Yes A nonempty list of selectors for prerequisite scripts.
requires No success (default) or completion.
phase No start or stop. Required for module-only rules that select both startup and shutdown scripts.

Every script selected by run waits for every script selected by after. The order of selectors within either list doesn't determine execution order. To declare a chain, use separate rules, such as configuration after preparation and tests after configuration.

Coder combines rules from all data sources in the template, including declarations inside modules. Repeated dependencies with the same requirement are valid. Declaring the same dependency with conflicting requires values is invalid.

A script can succeed before a background service it starts is ready. If a prerequisite starts a background service, check that the service is ready before the script exits. Redirect the background service's stdout and stderr, for example my-server > /tmp/server.log 2>&1 &. Otherwise, Coder can treat the prerequisite as failed and skip its requires = "success" dependents.

Selectors are quoted Terraform resource or module addresses, not resource IDs or display names. Selectors match only coder_script resources and modules, so you can't order the startup_script or shutdown_script attributes of coder_agent. Coder must be able to determine all coder_script_order input values when it imports your template. The data source doesn't need Terraform depends_on. Terraform's depends_on controls provisioning operations, not script execution inside a workspace.

Select scripts and modules

Coder resolves selectors relative to the module containing the coder_script_order data source:

Selector string Selects
coder_script.install All instances of a script resource in the declaring module.
coder_script.install[0] One count instance.
coder_script.install["api"] One for_each instance.
module.checkout Scripts across all instances of a direct child module, including nested descendants.

In Terraform strings, escape quotes around a for_each key: "coder_script.install[\"api\"]". An unindexed selector for a declared script or module can match no instances, such as with count = 0 or an empty for_each. That selector adds no dependencies. An unknown resource or module name, or an indexed script instance that doesn't exist, is invalid.

A parent module can select an entire direct child module. It can't select an individual script inside that module, a nested module path, or one indexed module instance. For example, module.checkout.coder_script.clone, module.checkout.module.tools, and module.checkout[0] aren't supported selectors.

Order scripts in modules

You can order modules without knowing their internal script names or changing their source. For existing checkout and application module calls, add:

data "coder_script_order" "modules" {
  rule {
    phase = "start"
    run   = ["module.application"]
    after = ["module.checkout"]
  }
}

Every startup script in application waits for every startup script in checkout to succeed. Scripts within each module remain concurrent unless other rules order them. The selected startup scripts must share one workspace agent or dev container sub-agent.

Wait for multiple prerequisites

You can combine module and script selectors in one rule. For example, this template clones Microblog and installs its system packages in parallel. It then installs the application's dependencies after both succeed:

module "checkout" {
  source   = "registry.coder.com/coder/git-clone/coder"
  version  = "2.0.5"
  agent_id = coder_agent.main.id
  url      = "https://github.com/miguelgrinberg/microblog.git"
}

resource "coder_script" "system_packages" {
  agent_id     = coder_agent.main.id
  display_name = "Install System Packages"
  run_on_start = true
  script       = "sudo apt-get update && sudo apt-get install -y python3-dev python3-venv build-essential"
}

resource "coder_script" "python_dependencies" {
  agent_id     = coder_agent.main.id
  display_name = "Install Python Dependencies"
  run_on_start = true
  script       = <<-EOT
    set -e
    cd ${module.checkout.repo_dir}
    python3 -m venv .venv
    .venv/bin/pip install -r requirements.txt
  EOT
}

data "coder_script_order" "app_setup" {
  rule {
    phase = "start"
    run   = ["coder_script.python_dependencies"]
    after = ["module.checkout", "coder_script.system_packages"]
  }
}

The git-clone module and Install System Packages can run concurrently. Install Python Dependencies waits for both to succeed. If either prerequisite fails, Coder skips Install Python Dependencies.

Order scripts in a dev container

This example builds a Node.js project at /workspaces/app inside an existing coder_devcontainer.app:

resource "coder_script" "devcontainer_install" {
  agent_id     = coder_devcontainer.app.subagent_id
  display_name = "Install Dependencies"
  run_on_start = true
  script       = "cd /workspaces/app && npm ci"
}

resource "coder_script" "devcontainer_build" {
  agent_id     = coder_devcontainer.app.subagent_id
  display_name = "Build Application"
  run_on_start = true
  script       = "cd /workspaces/app && npm run build"
}

data "coder_script_order" "devcontainer_startup" {
  rule {
    run   = ["coder_script.devcontainer_build"]
    after = ["coder_script.devcontainer_install"]
  }
}

Both scripts run inside the same dev container because they use its subagent_id as their agent_id. Build Application waits for Install Dependencies to succeed. For setup instructions, refer to Attach resources to dev containers.

Choose the lifecycle phase

Use phase = "start" for startup rules or phase = "stop" for shutdown rules. Coder filters module selectors to scripts in that phase. An explicit script selector must match the rule's phase and isn't filtered.

When you omit phase, Coder first infers it from the rule's explicit coder_script selectors. If those selectors match no script instances, Coder infers it from the module selectors when all selected scripts share one phase. A module-only rule containing both startup and shutdown scripts requires an explicit phase. If all selectors are valid but match no script instances, the rule has no effect.

When an inferred phase filters out module scripts, Coder reports a warning in the provisioner logs. Setting phase explicitly makes that filtering intentional and suppresses the warning.

Every script matched by a selector must set exactly one of run_on_start or run_on_stop. For module selectors, this includes scripts that Coder excludes because they belong to the other phase. If you need to order a script that runs at both startup and shutdown, split it into two coder_script resources, one per phase. Cron-only scripts can't be ordered, and ordering doesn't apply to scheduled cron executions.

Choose the required outcome

The requires attribute controls whether a prerequisite's result lets a dependent script run. All prerequisites must satisfy their requirements before the dependent starts:

Prerequisite result requires = "success" requires = "completion"
Succeeds Can run. Can run.
Fails Skips. Can run.
Times out Skips. Can run.
Is skipped Skips. Can run.
Execution is canceled Doesn't run. Doesn't run.

Use completion for scripts that must run even if a prerequisite fails, times out, or is skipped, such as cleanup and reporting scripts. For example, extend the earlier startup example with a rule for an existing coder_script.report startup script:

data "coder_script_order" "report" {
  rule {
    run      = ["coder_script.report"]
    after    = ["coder_script.install"]
    requires = "completion"
  }
}

This allows coder_script.report to run after coder_script.install succeeds, fails, times out, or is skipped.

If startup or shutdown execution is canceled, Coder cancels running scripts and doesn't start any remaining scripts. This applies to both requires = "success" and requires = "completion". In the example above, if startup execution is canceled while coder_script.install is running, Coder cancels it and doesn't run coder_script.report.

A script's execution timeout, set with the timeout attribute, starts when its body begins running. Time spent waiting for prerequisites doesn't consume that timeout. There is no separate dependency wait timeout, and scripts have no execution timeout by default. Set execution timeouts on prerequisites to bound how long dependents wait for scripts that don't finish.

Order shutdown scripts

Shutdown rules use the same dependency direction and outcome requirements as startup rules. Declare shutdown rules explicitly with phase = "stop". Startup dependencies don't automatically reverse during shutdown.

Coder resolves shutdown ordering when the workspace starts. The running agent uses those rules when the workspace stops or is deleted. To apply updated shutdown rules, start the workspace with the updated template version.

For example, export a development PostgreSQL database before compressing the dump:

resource "coder_script" "export_database" {
  agent_id     = coder_agent.main.id
  display_name = "Export Database"
  run_on_stop  = true
  timeout      = 30
  script       = "pg_dump app > /tmp/app.sql"
}

resource "coder_script" "compress_dump" {
  agent_id     = coder_agent.main.id
  display_name = "Compress Dump"
  run_on_stop  = true
  timeout      = 30
  script       = "gzip -f /tmp/app.sql"
}

data "coder_script_order" "shutdown" {
  rule {
    phase = "stop"
    run   = ["coder_script.compress_dump"]
    after = ["coder_script.export_database"]
  }
}

On shutdown, Compress Dump waits for Export Database to succeed before compressing /tmp/app.sql.

Configure the workspace runtime's termination grace period to exceed the longest shutdown chain. Allow additional time for script processes to terminate and for the agent to shut down. For example, add this attribute to the existing docker_container resource in a Docker workspace:

destroy_grace_seconds = 120

This gives the container up to 120 seconds to stop, including script execution, process termination, and agent shutdown. Other runtimes require an equivalent grace period, such as termination_grace_period_seconds in the Kubernetes Terraform provider. If the runtime terminates the agent before the chain finishes, the remaining scripts won't run.

Logs and build timeline

While a script waits, its log reports all remaining prerequisites in one entry every 30 seconds. Each entry identifies prerequisites by their full Terraform resource addresses. If Coder skips a script, its log names the prerequisites that failed, timed out, or were skipped. These messages use each prerequisite's display name, or its Terraform resource address if no display name is set. Cancellation logs distinguish scripts canceled before starting from scripts canceled while running.

The Build timeline shows skipped and canceled startup scripts. A script that never started has zero execution duration. The agent logs include output from shutdown scripts.

Validation

Coder validates script selectors and dependencies when you import a template or start a workspace. Running terraform validate alone doesn't check script selectors or dependencies.

Template import rejects unknown or unsupported selectors, incompatible lifecycle phases, self-dependencies, cycles, and conflicting requirements. Dependencies across agents or sub-agents don't fail template import, but they fail the workspace start build after Terraform apply.

Ordering supports scripts within one workspace agent or one dev container sub-agent. Dependencies between agents, between an agent and its sub-agent, or between different sub-agents aren't supported.

Migrate from coder exp sync

For dependencies between whole lifecycle scripts, you can replace script-level sync coordination with coder_script_order rules.

Declarative ordering uses the outcome of the whole prerequisite script. If a script calls coder exp sync complete before it finishes, split it into separate coder_script resources at that point before migrating.

Calling coder exp sync complete from an EXIT trap lets dependent scripts run even if the prerequisite script fails. With coder_script_order, the default requires = "success" skips dependent scripts after a failure. Use requires = "completion" if they need to run even after the prerequisite fails.

The default five-minute wait timeout of coder exp sync start doesn't carry over. If you rely on that limit, set the timeout attribute on prerequisite coder_script resources before migrating.

To migrate:

  1. Map each sync unit to its coder_script resource or child module selector.
  2. Add a rule with the waiting script in run and its prerequisites in after.
  3. Choose success or completion to match the intended failure behavior.
  4. Remove the corresponding sync calls and completion traps from those scripts.
  5. Publish the updated template.
  6. Restart a test workspace using the updated template version.
  7. Verify the execution order and required outcomes in its script logs.

The experimental coder exp sync workflow remains available for coordination inside script bodies. Its unit status commands don't inspect declarative script dependencies. Use script logs and the Build timeline to observe declarative ordering.

Learn more