https://pulumi.com logo
Title
b

busy-journalist-6936

03/08/2022, 4:55 PM
I'm going run try and ask this question intelligibly. Presume I have coded action A, and action B in my pulumi code base. Now imagine a conditional, I only wanted action A to execute when performing pulumi up, and I have action B which I only want to execute when performing pulumi destroy. Is this awareness exposed by something I can hook into with my code at this time?
🤔 1
1
s

stocky-wire-60053

03/08/2022, 4:59 PM
You could use the Automation API -- create your own CLI with "up" and "destroy" commands, execute your own code then call "up" and "destroy" through the API. https://www.pulumi.com/docs/guides/automation-api/
🙌 2
b

busy-island-31180

03/08/2022, 5:55 PM
curious if the create/destroy are related to the same resource?
s

stocky-wire-60053

03/08/2022, 6:13 PM
p

powerful-room-57148

03/08/2022, 6:43 PM
I have the same need… I’ll look into using the automation API, but it’d be simpler and easier for me if my regular project code could just “know” what’s happening when it’s called — if it’s going to be creating, importing, updating, or deleting a resource. Is there any way to detect this at runtime?
s

stocky-wire-60053

03/08/2022, 6:46 PM
@powerful-room-57148 See the links I posted to pulumi-command, I've not used them before but I think it may get you what you want. If you look at the announcements channel, it is introduced in the February releases video. https://pulumi-community.slack.com/archives/CB36DSVSA/p1645654940467199
p

powerful-room-57148

03/08/2022, 6:47 PM
Thanks! I did see the links, and followed them, but in my case I don’t need to run an external command, I need to run local code (functions etc) in certain situations.
s

stocky-wire-60053

03/08/2022, 6:48 PM
Ahh, gotcha -- though, if you wanted to really be hackish your "external command" could call and execute local code .... haha, holy-hack, but could be done : )
p

powerful-room-57148

03/08/2022, 6:49 PM
🤔 I kinda wish I could attach some kind of preflight/postflight functions to resources, and if those functions were passed an arg with info about the operation (create/update/destroy) that’d get me all I need
lol yeah… 10 years ago I might have done something like that!
the maintenance overhead of that sort of thing… I don’t like leaving puzzles for whoever will inherit my project down the road 😉
s

stocky-wire-60053

03/08/2022, 6:50 PM
I agree 100%, it was mostly meant to solicit a good laugh.
p

powerful-room-57148

03/08/2022, 6:51 PM
success!
has anything along the lines of preflight/postflight functions been considered at any point?