IaC Workflows: CI, Plan Pinning, Partial Ownership
Apply from GitHub Actions
railwayapp/config plans on PRs and applies the reviewed plan on merge. The plan job pins the change set, the environment's configEtag, and the .railway/ git tree; the apply job applies that artifact without re-evaluating the authoring file. If the environment changed after the plan, or the merged .railway/ tree isn't the planned tree, apply fails. Re-plan.
- Create a project token for the target environment, store as
RAILWAY_TOKENrepo secret. Project tokens are environment-scoped, so the workflow can only touch that environment. - Install the TypeScript SDK in the repo (
npm install railway) so the plan job can evaluaterailway.ts. - Add
.github/workflows/railway-config.yml:
name: Railway config
on:
pull_request:
types: [opened, synchronize, reopened, closed]
paths:
- ".railway/**"
permissions:
contents: read
pull-requests: write
actions: read
id-token: write
jobs:
plan:
if: github.event.action != 'closed' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: railwayapp/config@v1
with:
command: plan
railway-token: ${{ secrets.RAILWAY_TOKEN }}
apply:
if: github.event.action == 'closed' && github.event.pull_request.merged && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
- uses: railwayapp/config@v1
with:
command: apply
railway-token: ${{ secrets.RAILWAY_TOKEN }}Every PR touching .railway/ gets a plan comment with the diff (destructive changes marked). Merging is the approval. Fork PRs are skipped (no secrets). id-token: write + the Railway GitHub App posts the comment as the Railway bot; without it, comments come from github-actions.
For multi-repo partial setups, add this workflow to every repository, each with a project token for the target environment.
CI without the action (any provider)
railway config plan --out railway-plan.json --detailed-exit-code # 0 clean, 2 changes pending
railway config apply --plan railway-plan.json --yes --confirm-destructive--plan applies the saved change set as-is and fails if the live configEtag drifted or the checked-out .railway/ tree differs from the planned tree.
Partial ownership commands
Ownership lives on the Railway environment; inspect or change it even if the original authoring file is gone. Release/transfer require environment ADMIN access and change only ownership metadata: no resource changes, deletes, redeploys, or file edits.
railway config partials list # partial names + owned addresses (--json for full map + configEtag)
railway config partials transfer legacy-ops operations \
--resource service.api --resource service.admin --dry-run # preview a move
railway config partials transfer legacy-ops operations # move ALL of legacy-ops (omit --resource)
railway config partials release operations --dry-run # preview releasing ownership
railway config partials release operations # release whole partial (or --resource for select addresses)Resource addresses look like service.api, database.postgres.
Ownership rules enforced on every plan/apply
- Declaring a resource owned by another partial fails with
Cannot manage service "api": already managed by partial "web".Move the declaration to the owning repo, or transfer ownership first. - A file with no
partialexport fails in an environment that has named partials. - A named partial deletes only resources it owns; unowned/other-owned resources are left alone.
- Whole-project planning requires zero named ownership remaining: release every partial, verify with
partials list, then combine resources into one file and review the plan carefully (omitted resources get deleted).
After transferring or releasing
- Update the source file to stop declaring moved resources; add them to the destination file.
- Re-plan before applying either file. Ownership changes make saved plans stale.
- Don't re-apply an old named-partial config. It can reclaim released ownership.