Thread
#general
    b

    busy-journalist-6936

    6 months ago
    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?
    s

    stocky-wire-60053

    6 months ago
    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/
    b

    busy-island-31180

    6 months ago
    curious if the create/destroy are related to the same resource?
    s

    stocky-wire-60053

    6 months ago
    p

    powerful-room-57148

    6 months ago
    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

    6 months ago
    @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

    6 months ago
    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

    6 months ago
    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

    6 months ago
    🤔 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

    6 months ago
    I agree 100%, it was mostly meant to solicit a good laugh.
    p

    powerful-room-57148

    6 months ago
    success!
    has anything along the lines of preflight/postflight functions been considered at any point?