Search code examples
pulumi

How to trigger custom function on lifecycle events?


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.


Solution

  • 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.