a day ago
We are migrating all projects to IaC instead, which seems like an improvement.
We have railway config pull for each project and after that formatted the config alot easier to follow with comments, hardcoded references to make sure a typo in the UI ENV will not create issue and other stuff to make it very easy to follow when you read it.
Right now the only way to add a database+volume seems to be with the UI, but if I then want to have that new database+volume in my config I need to go to a temp folder, railway link, pull the config, find the new database+volume, C/P that to the current config and validate with plan.
This seems like a step in the wrong direction.
Ideally when we do the cutoff we don't want developers to use the UI for anything other then select/view stuff. Instead we end with a confusing setup, where some functions cant be done with IaC.
I also tried to config pull --json, which dosen't require me to switch folder to a temp folder, but that format is completely different from the orginal config(.ts) file.
I can think of different solutions for this.
- Make it possible to spin up a new database+volume with IaC
- Make a config pull option that only adds whatever the plan shows as changes
- Make an --typescript or whatever flag so you can pull the config into the same folder at least.
Option #1 seems like "the way to go", but at least when I checked the docs, that dosen't seems possible, unless I take the --json format and find the volume mount and maybe try to add that to the database.
4 Replies
Status changed to Awaiting Railway Response Railway • 1 day ago
a day ago
I played around and found a kinda hacky solution:
const postgresVolumeIacTEST2 = volume("postgres-volume-iactest2", {
alerts: { usage: { "100": {}, "80": {}, "95": {} } },
allowOnlineResize: true,
region: "europe-west4-drams3a",
sizeMB: 50000,
});
const PostgresIacTEST2 = postgres("Postgres - Iac TEST 2", { region: "europe-west4-drams3a" });
PostgresIacTEST2.deploy = { multiRegionConfig: { "europe-west4-drams3a": { numReplicas: 1 } } };
PostgresIacTEST2.volumeAttachments = {
"postgres-volume-iactest2": {
volume: postgresVolumeIacTEST2.address,
mountPath: "/var/lib/postgresql/data",
},
};
This seems to spin up new postgres + mount the volume. Only issue is that if I run plan afterwards it shows changes
Plan: 0 to add, 1 to change, 0 to destroy
~ Update Postgres - Iac TEST 2 volumeAttachments.postgres-volume-iactest2.mountPath, volumeAttachments.postgres-volume-iactest2.volume
└ volumeAttachments.postgres-volume-iactest2.mountPath (null → "/var/lib/postgresql/data")
└ volumeAttachments.postgres-volume-iactest2.volume (null → "volume.postgres-volume-iactest2")
Because it checks versus the defaults values, which I have just "hardcoded" in this case.
So after the first plan applies I need to remove the block for volumeAttachments, and then it shows 0 changes.
madsmhm
I played around and found a kinda hacky solution: ```typescript const postgresVolumeIacTEST2 = volume("postgres-volume-iactest2", { alerts: { usage: { "100": {}, "80": {}, "95": {} } }, allowOnlineResize: true, region: "europe-west4-drams3a", sizeMB: 50000, }); const PostgresIacTEST2 = postgres("Postgres - Iac TEST 2", { region: "europe-west4-drams3a" }); PostgresIacTEST2.deploy = { multiRegionConfig: { "europe-west4-drams3a": { numReplicas: 1 } } }; PostgresIacTEST2.volumeAttachments = { "postgres-volume-iactest2": { volume: postgresVolumeIacTEST2.address, mountPath: "/var/lib/postgresql/data", }, }; ``` This seems to spin up new postgres + mount the volume. Only issue is that if I run `plan` afterwards it shows changes ```log Plan: 0 to add, 1 to change, 0 to destroy ~ Update Postgres - Iac TEST 2 volumeAttachments.postgres-volume-iactest2.mountPath, volumeAttachments.postgres-volume-iactest2.volume └ volumeAttachments.postgres-volume-iactest2.mountPath (null → "/var/lib/postgresql/data") └ volumeAttachments.postgres-volume-iactest2.volume (null → "volume.postgres-volume-iactest2") ``` Because it checks versus the defaults values, which I have just "hardcoded" in this case. So after the first plan applies I need to remove the block for volumeAttachments, and then it shows 0 changes.
a day ago
This didnt attach the volume correct, but if I leave out the volume block etc.
const PostgresIacTEST3 = postgres("Postgres - Iac TEST 3", { region: "europe-west4-drams3a" });
PostgresIacTEST3.deploy = { multiRegionConfig: { "europe-west4-drams3a": { numReplicas: 1 } } };
It spins up local postgres with a volume attached, but I still need to config pull that afterwards to get it in my IaC.
a day ago
Option 1 already works: your TEST 3 snippet is the right way to do it. postgres() sets up the database and its data volume itself, so you don't declare a volume() or volumeAttachments for it, and you don't need to pull afterwards. A plan after the apply should show no changes. Apply never deletes volumes that aren't declared in the file, so the database's volume can stay out of your config.
That's also what happened in TEST 2. The postgres() helper doesn't use a volumeAttachments block, so postgres-volume-iactest2 was created but never mounted, and plan keeps showing the attachment as a change because Railway never reports one back for a database. Dropping the block was the right fix. If that volume is still sitting unattached in the project, you can delete it from the dashboard so you're not paying for it.
The confusing part is config pull: it can write a database's volume out as a separate volume() next to the postgres() call, which makes it look like you need to declare one. You don't, and you can leave that line out of hand written config.
One gap for your cutover: custom domains can't be registered from IaC yet. You add them in the dashboard and then pull them into your config.
You're right that pull can't write somewhere else or merge into an existing file today, and --json gives the raw graph rather than TypeScript. I'll pass options 2 and 3 on to the team.
Status changed to Awaiting User Response Railway • 1 day ago
2 hours ago
One addition to Sam's note. If you want the size and alerts in the file, put them on postgres() itself:
postgres("Postgres - Iac TEST 2", {
region: "europe-west4-drams3a",
volume: {
sizeMB: 50000,
alerts: { usage: { "80": {}, "95": {}, "100": {} } },
},
})That is the volume the helper already creates, not a second one. A plan after apply should be empty.