I have some code which initializes a database (cre...
# general
l
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
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
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
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