Hi all, I would like to check the length of an Out...
# general
s
Hi all, I would like to check the length of an Output before using the value (in Python). Specifically, I’d like to write somthing like this, since if I don’t check, I get an index out of bounds when I create the service for the first time (this is for a GCP Cloud Run service):
Copy code
if len(svc.statuses)>0:
        pulumi.export("url", Output.concat(svc.statuses[0].url))
But Output objects don’t have a length, and a try / catch doesn’t stop Pulumi from crashing. How would I check for that value to be available before exporting it?
1
l
Output the result of the check. Do the check inside the apply, and output either the correct value, or the correct "there is no value" value (in typescript, that would be undefined).
s
That makes sense, I’ll give that a shot, thanks
👍 1
r
Copy code
url = svc.statuses.apply(lambda statuses: statuses[0].url if statuses else None)
pulumi.export("url", url)
👍 2
s
That worked, thanks! ✌️
partypus 8bit 1