How can my python callback function know if it's p...
# general
How can my python callback function know if it's pulumi up or it's pulumi destroy? I found there is
. I want to my callback
to handle the up and destroy differently but can't figure it out
As a workaround you could pass in an environment variable with the operation.
thanks but dont think that's a good idea... I dig into the SDK can see I can get project stack but can't know if that's the destroy or up
your program doesn't currently run at all during destroy. We're looking at adding this feature this year so that you can run real functions on create/update/destroy.
For now the recommendation is generally to make use of the command provider to hook up a dependent command resource that gets destroyed at the same time and run a command via that
@echoing-dinner-19531 do you mind you be more specific on command provider to hook up a dependent command resource? as far as I know pulumi doesn't support the dependence like terraform. that's why I use
Command provider: And you can make any resource depend on another one with the depends on property: Then just delete the main resource and the command resource in the same deployment and you'll get the commands destroy function run at the right time. And as I said, we are looking at making this more first class and well supported.
thanks. it doesn't help in my case based on my understanding. I need to run commands when the resource is created( lets say
hello world create the resource
) but a little different commands when resource is destroyed(
hello world destroy the resource
) I will need to know if this is pulumi up or destroy no matter I use
Command resource can run different commands on Create vs Delete. So if you make that resource side-by-side with your other resource then you can get create and delete triggers at the right time. Wrap it all up in a component resource or function and its even pretty re-usable.
thanks and finally got it... I hope you can add this feature soon. so I don't have write command wrapper to call another python script or bash command on create/delete