Skip to content

Config planning fails for shared variables in IaC file #1117

Description

@voidmain

The new IaC fails on all shared variables, even when it is linked to a valid project, in a valid environment, with a valid shared variable.

Example:

Project: Foo
Env: production
Shared value: BAR="some-value"

railway.ts:

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

const REGION = "us-east4-eqdc4a";

export default defineRailway((ctx) => {
  const baz = service("baz", {
    env: {
      BAR: ctx.shared.BAR
    },
    healthcheck: "/api/status",
    replicas: { [REGION]: 1 },
    source: github("some-repo", { branch: "main" }),
  });

  return project("Project Name", {
    resources: [baz],
  });
});

This fails with an error something like this:

node failed to evaluate IaC file.
file:///Users/user/dev/project/.railway/railway.ts?t=1787413491413:24
      BAR: ctx.shared.BAR

TypeError: Cannot read properties of undefined (reading 'BAR')
    at file:///Users/user/dev/project/.railway/railway.ts?t=1787413491413:24:37
    at file:///Users/user/dev/project/[eval1]:10:56

Node.js v26.7.0

Claude suggested what looked like a horrible hack of creating a context if there wasn't one, but I've tested that and it seems to delete the shared variables in Railway in some cases.

This shouldn't fail as it is documented here: https://docs.railway.com/infrastructure-as-code/reference#environment-variables

This should pull from the project/environment and check that the variable exists (which it does) and then happily continue with the planning stage.

Unless I'm doing something seriously wrong, this is basically a showstopper for IaC since any secrets can't be managed outside of the Typescript file.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions