https://pulumi.com logo
#general
Title
# general
l

little-market-63455

07/15/2021, 2:11 PM
I have some code which initializes a database (creates, grants privileges and so on) if it is not already initialized and should delete it on
destroy
. I am not using the automation API and wondering if there is a property somewhere that tells me what mode is the CLI running under like
up
,
destroy
,
refresh
,
preview
and so on. I check
pulumi.runtime
but it doesn't seem to expose this. I am probably not doing it the correct way, maybe dynamic providers?
b

bored-oyster-3147

07/15/2021, 2:33 PM
in your pulumi code you can check for
IsDryRun
which tells you if it is
preview
. That is so you can omit work that should only run during an
up
. Both
refresh
and
destroy
don't actually execute your pulumi code so it isn't necessary to check for them
🙌 1
l

little-market-63455

07/15/2021, 4:04 PM
hmm but I do want to run some code on
destroy
for cleanup but I guess that should live elsewhere. Thanks for the tip though 👍
b

bored-oyster-3147

07/15/2021, 4:06 PM
Np. Yea you'll have to do post-destroy work independently of your call to
pulumi destroy
. Because
pulumi destroy
just loads your providers and destroyed what is currently in your state, which is why it doesn't execute your pulumi code