https://pulumi.com logo
#google-cloud
Title
# google-cloud
s

stocky-window-81967

02/17/2021, 2:03 AM
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

billowy-army-68599

02/17/2021, 3:05 AM
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

stocky-window-81967

02/17/2021, 3:35 AM
that makes sense
thanks
ahhhh didn't realize I could use Outputs and just skip if I created the notification channel already
g

green-school-95910

02/17/2021, 11:05 AM
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
3 Views