https://pulumi.com logo
Title
s

strong-helmet-83704

03/13/2023, 9:39 PM
Hi all, kind of a basic question i guess… how would we detect if pulumi is running in Preview, Up or Destroy mode from our Python project?
l

limited-rainbow-51650

03/13/2023, 9:55 PM
You can check between
preview
and
up
using the
is_dry_run
function from the core Pulumi SDK: https://www.pulumi.com/docs/reference/pkg/python/pulumi/#pulumi.runtime.is_dry_run When
destroy
runs, the language host is not involved as Pulumi destroys the resources based on what is in the state, not what is in your Pulumi program.
s

strong-helmet-83704

03/13/2023, 10:07 PM
🙌
is there an equivalent for
destroy
?
l

limited-rainbow-51650

03/14/2023, 6:40 AM
No, because during
destroy
, your program isn't loaded. As mentioned above, Pulumi deletes the resources it can find in the state of your stack. Can you explain why you would need it during
destroy
?
s

strong-helmet-83704

03/14/2023, 4:53 PM
Right, good point. I am reaching out to an external database doing crud operations
Perhaps i need to create a custom resource, or custom provider
l

limited-rainbow-51650

03/14/2023, 5:51 PM
@strong-helmet-83704 is this what you are after? https://github.com/pulumi/pulumi/issues/9397
s

strong-helmet-83704

03/14/2023, 6:02 PM
kinda… I did consider wrapping the program to perform cleanup tasks outside of Pulumi… but this seems less neat
The other thing i could do is refactor the program with automation api and have a custom interface for invoking my program. but this is a major overhaul and automation api does not have all the features of the regular cli
i think for now the best bet might be https://www.pulumi.com/docs/intro/concepts/resources/dynamic-providers/ @kind-jelly-61624