Skip to content
IaC does not feel production ready for real projects
therobotcarlson
OP

2 months ago

I was asked to copy this here from Discord:

9/12/26, 8:19 PM

I tried experimenting with railway IaC since I see what I was previously using without issue (Config-as-Code) was being has been deprecated.

Tested on CLI 5.49.2, including a fresh project. Routine service additions, updates, and removals worked; these issues remained:

  • Invalid generated TypeScript: config pull emitted duplicate declarations for a repository and service sharing a name, causing the untouched export to fail planning.
  • Migration path resolution: config migrate treated /frontend/railway.json as an absolute filesystem path and reported it missing, although frontend/railway.json existed in the repo.
  • Inconsistent cross-environment identity: redis("cache") failed in a second environment because the name already existed in the project, while ordinary services reused their identities successfully. Separate database names work around this.
  • Plan misses a predictable failure: The database-name conflict above passed planning as a safe creation and surfaced only during apply.
  • Redis reconciliation mismatch: A Redis image declared through service(...) applied successfully, but an unchanged plan proposed deleting a database and creating a service. Using redis(...) produced no changes.
  • Misleading JSON success: Failed applies returned top-level "ok": true; the failure and diagnostic appeared only inside applyResult.
  • One thing I liked about the Config-as-Code was that it was a Railway-executed config and very simply configurable per repo. IaC requires a user-created and maintained workflow for applying changes.
  • Most of my environments / projects are multi-repo. This IaC config seems to prefer monorepo and calls having config in separate repos (named partials) a "last resort".
  • To clarify, I would prefer something like partials as a first class construct instead of "last resort"

New additions (Oct 2):

One additional problem, which exists for any "self-applied" IaC: you can erase and break things trivially. Agents exponentially increase the risk associated with this. It's like putting a "nuke everything" button beside the enter button. It's just a matter of time before an accident happens.

In the old config-as-code, all changes had to go through github and review and were trivially scoped to the repo and / or code that was associated with them. This meant that you could delay a change getting to prod trivially by not merging the release branch. With proper github guardrails, this makes it nearly impossible for agents to modify config in railway accidentally (obviously still possible with the CLI, but it is harder to break things at scale). To use IaC safely, I basically have to ensure all my agents everywhere don't have access to the railway CLI and only wait for a plan on PRs to verify their infra changes. That's not an ideal development workflow.

"@therobotcarlson", you say, "surely you can just use our github action to plan and apply your IaC safely?"

The railway github action doesn't understand different deploy environments. It uses a railway token, which is scoped to only a specific environment. So every person that has a dev and prod split can't use railway's action. (Or have to figure out environment-scoped secrets in github)

What about long lived feature branch deployments with infra changes? You can't iterate on infra changes in a fresh env without making and adding new railway tokens to github?

All that said, I love the idea, I just wish it had more time to bake as optional before forcibly removing something that worked and replacing it with something not equivalent: worse in some regards, better in others.

Idealized model:

  • Each repo defines its own IaC - this is possible through named partials now. (orgs who separate their IaC into specialized infra repos are living in the past, but monorepos are a different kind of ick)
  • Railway applies that IaC from a commit. Does this look like a separate service? Maybe? An env config? Either way, somewhere I say, "I have IaC I want to deploy from this repo" and then I add another repo with more IaC that can all live in the same environment and is ONLY applied to that environment. The impact is scoped. If I merge a PR, it should only be able to nuke one environment at a time.
  • A railway app that comments the plan diffs on PRs. Charge us for the compute if you must. Railway is already linked to my github and can make PRs. Railway has permission already.
Under Review

0 Threads mention this feature

11 Replies

Status changed to Awaiting Railway Response Railway • about 2 months ago


therobotcarlson
OP

2 months ago

It seems some of the language around named partials being "last resort" has been removed from the docs page since my initial post in Discord: https://docs.railway.com/infrastructure-as-code#multi-repo-projects / https://github.com/railwayapp/docs/pull/1356/

Are they first class constructs now? 😄


rfree18

a month ago

+1 to all of this. This feels extremely rushed and not a suitable replacement to config as code. If config as code is truly going to cease being supported on 12/1, then we're likely going to resort to dropping managing this in code altogether and revert to using the dashboard. This is highly unfortunate since we'd lose all of the benefits of git for managing our configurations.


sov3rain

20 days ago

Agree. Losing config as code is a bummer. We are already dropping managing configuration in code altogether.


jscheel

8 days ago

Is there anyone from the team that can weigh in here? IaC still does not feel ready, and the deadline is looming.


Hey all, thanks for writing this up in such detail.

What's already fixed: The OP tested on CLI 5.49.2. Most of the issues reported were fixed in 5.57.6-5.57.8, a few days after the original post:

  • config pull no longer generates duplicate declarations when a repo and a service share a name
  • config migrate handles paths like /frontend/railway.json relative to the repo
  • A database like redis("cache") now reuses its existing identity in a second environment, the same way services do
  • Database name conflicts now fail at plan, as expected
  • A Redis image declared with service(...) no longer produces a delete-and-recreate plan
  • A failed apply now exits non-zero

Named partials are also now a first-class way to set up multi-repo projects. The "last resort" wording is gone, and there's a multi-repo guide. railway config partials list / partials transfer manage which partial owns what. Long improvement road ahead, but please update to the CLI and give it a short.

Migration: railway config migrate has improved a lot. It now offers guided cutover you can undo (cutover / undo), and lets you choose explicitly how variables are handled upfront.

Official GitHub Action. railwayapp/config runs plan on every PR that touches .railway/ and posts the diff as a PR comment from the Railway bot, with destructive changes flagged. On merge, it applies, and fails if environment has drifted in the meantime. Destructive changes need confirmation. Your config also gets an evaluation context (ctx), so it can tell when it's running in a PR environment and branch accordingly.

What we're working on:

  • Easier targeting of multiple environments from one setup. We're testing a few different ideas, but we'd love to hear what your ideal experience would look like.
  • Proper support for ephemeral environments
  • Better support for secrets managed outside Railway

On auto-apply: Railway not applying IaC automatically on push, the way CaC did, is a deliberate choice. It's how established IaC tools like Terraform work too: you see a plan, someone approves it, and the apply happens as its own deliberate step. That way, a stray push can't change your infrastructure.

On a final note: CaC end of life date is December 1st, but ping us if IaC is incompatible with your workflow so we can take a look into your case.

Please keep the feedback coming, thank you so much for your contributions.


futurepastori

Hey all, thanks for writing this up in such detail. **What's already fixed:** The OP tested on CLI 5.49.2. Most of the issues reported were fixed in 5.57.6-5.57.8, a few days after the original post: * `config pull` no longer generates duplicate declarations when a repo and a service share a name * `config migrate` handles paths like `/frontend/railway.json` relative to the repo * A database like `redis("cache")` now reuses its existing identity in a second environment, the same way services do * Database name conflicts now fail at `plan`, as expected * A Redis image declared with `service(...)` no longer produces a delete-and-recreate plan * A failed apply now exits non-zero Named partials are also now a first-class way to set up multi-repo projects. The "last resort" wording is gone, and there's a [multi-repo guide](https://docs.railway.com/infrastructure-as-code#multi-repo-projects). `railway config partials list` / `partials transfer` manage which partial owns what. Long improvement road ahead, but please update to the CLI and give it a short. **Migration**: `railway config migrate` has improved a lot. It now offers guided cutover you can undo (`cutover` / `undo`), and lets you choose explicitly how variables are handled upfront. **Official GitHub Action**. [railwayapp/config](https://github.com/railwayapp/config) runs plan on every PR that touches .railway/ and posts the diff as a PR comment from the Railway bot, with destructive changes flagged. On merge, it applies, and fails if environment has drifted in the meantime. Destructive changes need confirmation. Your config also gets an evaluation context (`ctx`), so it can tell when it's running in a PR environment and branch accordingly. **What we're working on**: * Easier targeting of multiple environments from one setup. We're testing a few different ideas, **but we'd love to hear what your ideal experience would look like**. * Proper support for ephemeral environments * Better support for secrets managed outside Railway **On auto-apply**: Railway not applying IaC automatically on push, the way CaC did, is a deliberate choice. It's how established IaC tools like Terraform work too: you see a plan, someone approves it, and the apply happens as its own deliberate step. That way, a stray push can't change your infrastructure. On a final note: CaC end of life date is December 1st, but ping us if IaC is incompatible with your workflow so we can take a look into your case. Please keep the feedback coming, thank you so much for your contributions.

therobotcarlson
OP

5 days ago

Hi, thanks for getting back to us.

Easier targeting of multiple environments from one setup. We're testing a few different ideas, but we'd love to hear what your ideal experience would look like.

No serious production workload with customers is using a single environment. Why is lack of good multi-environment support something that is not being considered blocking for declaring this ready?

It's how established IaC tools like Terraform work too

Terraform is a terrible industry standard that I do not think is worth emulating. CaC was another option, which is the point. There is no differentiation in auto-deploy capability between CaC and Railway IaC if you're running the railway github action. The only difference is one additional point of failure from the github action. If people do not want "stray pushes", they should have branch protection -- that is industry standard. IaC will not stop "stray pushes" from changing infrastructure.

CaC end of life date is December 1st

My primary concern is that this date is approaching too soon and that railway has seemingly not evaluated real production workloads / workflows using it. Railway has been extremely quiet on resolving these issues, seemingly just ignoring user concerns.

My post is not the only one:

There are more, but I think my point was made^

So in summary:

  • First class multi-environment support should be a blocking requirement
  • Terraform is bad and should not be emulated
  • Auto-apply infra was the feature, not a bug
  • Railway IaC does not stop auto-apply, it just adds additional points of failure like github actions -- you should know how often Github is down these days.
  • Rushed rollout means bugs / these concerns don't get properly resolved before the deadline

jingan-chen-generis

5 days ago

Fully agree with everything OP said above.


codan84

a day ago

100% agree with all of the above. The IaC feels like a side-project rather than a production ready tool. Unsure why we are not getting a Pulumi provider tho (imho Pulumi is brilliant).

The main issue with IaC I have is HA/databases. All services I create via IaC are environment-scoped, so I can for example write the below and apply on all my environments as needed:


import { defineRailway, project, service } from 'railway/iac';

export default defineRailway(() => {
  const myService = service('my-service', { //...// });
  return project('my-project', { resources: [myService] });
})

But for some reason DBs are project-scoped, so using DB helpers lets me only apply IaC in 1 env for the project, all other envs will not provision DB correctly, ie:


import { defineRailway, project, mongo } from 'railway/iac';

export default defineRailway(() => {
  const myDb = mongo('mongo');
  return project('my-project', { resources: [myDb] });
})

I tried to do trickery like postfixing my DB name with env (const myDb = mongo('mongo-${env}')), but then you have further issues when converting DB deployed this way to HA as subsequent applys will attempt to reset startup scripts etc on one of the HA nodes (the original one that was converted to HA). Absolutely terrible experience, and none of this is documented. I essentially had to manually deploy my DBs and mark my IaC as partial, even though I am working with a monorepo and all my services are deployed from 1 railway IaC file.


codan84

a day ago

Further issues I noticed:

  • secrets are not reported back properly when planning/applying, so every plan/apply will report these as candidates for replacement (they won't actually be replaced fortunately). I had to build my own workaround for this (below)
  • custom external domains (ie ones registered in Cloudflare) can't be added via IaC, they also can't be preserve()'d via IaC (preserve only works for variables) - so the only way to correctly structure the deployment here is to again add a workaround script (below)
import { execFileSync } from 'node:child_process';
import { preserve, type RailwayContext } from 'railway/iac';

const isRecord = (value: unknown): value is Record<string, unknown> =>
  value !== null && typeof value === 'object' && !Array.isArray(value);

type RailwayState = ReturnType<typeof loadRailwayState>;
let currentState: RailwayState | undefined;

export const getRailwayState = (): RailwayState => {
  if (!currentState) {
    throw new Error('Load Railway state in the root configuration before accessing it');
  }
  return currentState;
};

// Pull imports variable names and networking without decrypting secret values.
export const loadRailwayState = (context: RailwayContext) => {
  currentState = undefined;
  const environment = context.environmentId ?? context.environment;

  if (!environment) {
    throw new Error('An explicit Railway environment is required to read current configuration');
  }

  let snapshot: unknown;
  try {
    snapshot = JSON.parse(
      execFileSync('railway', ['config', 'pull', '--environment', environment, '--json'], {
        encoding: 'utf8',
        timeout: 30_000,
        stdio: ['ignore', 'pipe', 'pipe'],
      }),
    );
  } catch {
    throw new Error(
      'Could not read Railway configuration; refusing to generate secrets or resolve domains',
    );
  }

  if (!isRecord(snapshot) || !Array.isArray(snapshot.resources)) {
    throw new Error('Invalid Railway configuration snapshot');
  }

  const existingSecrets = new Map<string, Set<string>>();
  const existingDomains = new Map<string, Set<string>>();

  for (const resource of snapshot.resources) {
    if (
      !isRecord(resource) ||
      typeof resource.name !== 'string' ||
      (resource.variables != null && !isRecord(resource.variables))
    ) {
      throw new Error('Invalid Railway configuration snapshot');
    }

    existingSecrets.set(resource.name, new Set(Object.keys(resource.variables ?? {})));

    if (resource.type !== 'service' || resource.networking == null) {
      continue;
    }

    if (!isRecord(resource.networking)) {
      throw new Error('Invalid Railway configuration snapshot');
    }

    const customDomains = resource.networking.customDomains;
    if (customDomains == null) {
      continue;
    }

    if (!isRecord(customDomains)) {
      throw new Error('Invalid Railway configuration snapshot');
    }

    const registeredDomains = new Set<string>();

    for (const [domain, configuration] of Object.entries(customDomains)) {
      if (configuration === null) {
        continue;
      }

      if (!isRecord(configuration)) {
        throw new Error('Invalid Railway configuration snapshot');
      }
      registeredDomains.add(domain);
    }

    existingDomains.set(resource.name, registeredDomains);
  }

  const secret = (service: string, variable: string) =>
    existingSecrets.get(service)?.has(variable)
      ? preserve()
      : { generator: '${{secret(64, "abcdef0123456789")}}' };

  const customDomain = (service: string, domain: string, port: number) =>
    existingDomains.get(service)?.has(domain) ? [{ domain, port }] : undefined;

  const state = { secret, customDomain };
  currentState = state;
  return state;
};

Usage:

const myService = service('my-service', {
  domains: customDomain('my-service', 'my-domain.example.com', 8080),
  env: {
    MY_SECRET: secret('my-service', 'MY_SECRET'),
  }
  //...//
}

All of these I'd expect to be handled correctly out of the box...


codan84

a day ago

Even more if I may add - around mongo and redis and postgres helpers etc! These always deploy with default settings on 1st apply, even if some of these settings have been changed (a startup script for mongo for example). Only subsequent applies deploy custom settings specified in IaC. I know this is probably not due to IaC itself but due to special provisioning pipelines for these DBs, but these should in that case be updated to support custom values on the initial provision. Otherwise IaC is not deploying what is specified in code.

Man I have spent a lot of time working with Railway. I like it a lot! But IaC sucks badly...


3 hours ago

I really liked this offering when it first landed as it's given us more flexibility (and in an easier way) than CaC did, but I have to agree - having been using it for a while, there are a lot of pain points. We're still running CaC in our main project for this reason.

I think the correct course of action on Railway's part here would be to extend the life of CaC until IaC is more mature.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...