Is anyone running arbitrary NodeJS `child_process`...
# general
l
Is anyone running arbitrary NodeJS
child_process
functions (e.g.
spawn
,
spawnSync
) in their Pulumi applications? E.g. suppose you want to set up an SSH tunnel midway through a Pulumi process, after e.g. provisioning a bastion host, so rough pseudo code:
Copy code
const bastion = new cloudProvider.Instance(...)

spawnSync("ssh", ["-L", ...])

const database = new postgresql.Database(..., {
  host: "localhost" // the host is localhost because of the tunnel we've set up
})
I can see a few ways to go about this: 1. Use Pulumi automations, in which I orchestrate the "pre-tunnel" and "post-tunnel" bits. There's an example of this online, but I'm somewhat wary of this as I'd like to maintain access to the "standard" Pulumi CLI and its features if possible, which I understand automations would take me away from 2. "Just call the function" in the middle of the Pulumi program -- I think this is OK? Perhaps it needs wrapping in an
apply
or something and feeding into another
dependsOn
? https://github.com/pulumi/pulumi-kubernetes/issues/1857 seems to suggest this is possible but the equivalent TypeScript code appears to be type incorrect (though I may be missing something obvious) 3. Use something like
@pulumi/command
, though since I want the tunnel to be created on every run, this feels wrong, since I'd not want it to go in the state file. But again, could be wrong here. All thoughts and input welcome/gratefully received 🙏
s
I'd recommend
@pulumi/command
. I haven't used it yet (I've only used local.Command), but it seems like you want remote.Command: https://www.pulumi.com/registry/packages/command/api-docs/remote/command/
To make the command execute on every run, try: https://www.pulumi.com/registry/packages/command/api-docs/remote/run/
l
I'd not seen
run
-- thanks!