Can anyone answer if there's a way to "find or cre...
# google-cloud
s
Can anyone answer if there's a way to "find or create" a resource using pulumi?
I'd like to try to find an existing
gcp.monitoring.get_notification_channel
or create one if it doesn't exist... versus just fail on either the get or resource create. I'm basically iterating over a bunch of resources and attaching a notification channel to them. I don't want to loop twice, as in first creating whatever notification channels need to exist prior to creating the alerts. I'd rather just create them as a I need them and look up (or create) the channel on the second time I need it.
I can do this with a direct API client but was hoping Pulumi had something... which I'm doubtful of.
b
this isn't really following the model of how pulumi works. Pulumi drives towards a desired state, so if the resource doesn't exist, it will create it. You can do a lookup with the direct api and then do an if statement to create the resource
s
that makes sense
thanks
ahhhh didn't realize I could use Outputs and just skip if I created the notification channel already
g
You can also "adopt" resource that already exists by setting the import field in the options. It only needs to be done once, after that pulumi manages that resource like any other