I'm going run try and ask this question intelligib...
# general
b
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
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
curious if the create/destroy are related to the same resource?
s
p
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
@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
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
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
🤔 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
I agree 100%, it was mostly meant to solicit a good laugh.
p
success!
has anything along the lines of preflight/postflight functions been considered at any point?