How do you do something only when a resource is actually created or destroyed.
Like say i'm generating a value and storing it in a db every time an ec2 is created. But i only want to actually store the value if pulumi is actively creating the resource (or dropping it if the resource is being destroyed)
Seems like the only place i can do something like that is a dynamic provider, but that also just seems really heavy handed and like i'm missing some sort of ".on('create')" event or something
g
gentle-diamond-70147
04/05/2021, 9:10 PM
Dynamic provider is the way to do this right now. Pulumi doesn't currently support lifecycle hooks like you describe.
b
bored-oyster-3147
04/06/2021, 1:34 PM
I suppose you could use automation API and use the new structured logging to subscribe to pulumi engine events and depending on the event you could do some action. Haven’t explored that use case though
g
gentle-diamond-70147
04/06/2021, 6:13 PM
Yep, that sounds like a good option too. The value that you're storing or dropping would not have the same resource management lifecycle of a pulumi resource (with Create/Read/Update/Delete), but that might be okay for this use case.