if I use hooks to open ssh tunnel for multiple res...
# general
h
if I use hooks to open ssh tunnel for multiple resources, pulumi will run
ssh
for each resource change, right?
e
yes, hooks run on every resource change
l
That said, they share program state, so you could e.g. (I think) have your hook call a function that caches the tunnel.
E.g.
Copy code
let tunnel: ChildProcessWithPidOrWhateverIForgetTheExactTypeName
function openTunnel() {
  if (tunnel) {
    return tunnel
  }

  // try/catch etc. might be useful
  tunnel = spawnSync("ssh", ...)
  return tunnel
}

function closeTunnel() {
  tunnel?.kill(SIGKILL) // etc.
}

const x = new Resource("x", ..., { hooks: { beforeCreate: [openTunnel], ... } })
💡 1
I think
I suspect race conditions are possible though so you might want a lock etc.
h
that looks kinda like a temporary resource. Unless this is the only one use for such a construct, perhaps it should be explicitly supported by pulumi? I use a bastion node and my workaround is to run
BASTION=true pulumi up
which starts it, uses to create any resources from
command
module, and then
pulumi up
which destroys the bastion I could also use something similar for
kubectl port-forward
e
perhaps it should be explicitly supported by pulumi?
Yeh I've thought about this. I don't think it would be that tricky to support if needed, the main thing is working out the lifecycle for deletes. It's easy if we just say temporarys get deleted at the end, but if we need smaller lifetimes than the whole program that gets tricky.