1

How do I instruct Pulumi to invoke my custom Typescript function when pulumi up or pulumi destroy is invoked from command-line?

I tried invoking my function from the main code block, but it is getting invoked multiple times on pulumi up.

Further, there are some commands I only want to invoke for up and others that should only be invoked for destroy.

Gili
  • 86,244
  • 97
  • 390
  • 689

2 Answers2

1

You can use pulumi.runtime.isDryRun() to run code or functions only during update. Pulumi doesn't currently expose a way to hook into lifecycle events, but this is on the roadmap at https://github.com/pulumi/pulumi/issues/1691.

Cameron
  • 431
  • 3
  • 3
0

If you are ok with this function to be called async you can wrap your stack using Pulumi Automation API and provide onEvent option when invoking it using TypeScript:

stack.up({
  onEvent: (event) => {
    if (event["preludeEvent"] !== undefined) {
      // run something once before changing resources
      return
    }
  },
})

The same can be done during destory


  • github.com - more details on what types of events are available.
  • dev.to - detailed blog about using pulumi automation events
Artem Yarmoliuk
  • 306
  • 1
  • 5