I'm creating a GCP storage bucket and aggregated log sink using Pulumi and Python. To create the sink I need the value of the bucket id from Pulumi.
bucket = storage.Bucket(resource_name=bucket_name,
location="us-central1",
storage_class="REGIONAL",
uniform_bucket_level_access=True)
# destination value is needed to create the logging sink.
destination = Output.all(bucket.id).apply(lambda l: f"storage.googleapis.com/{l[0]}")
print(destination)
I would expect to get a print output of the destination variable similar to "storage.googleapis.com/bucket_id"
. Instead I am getting
<pulumi.output.Output object at 0x10c39ae80>
. I've also tried using the Pulumi concat method as described at the Pulumi docs.
destination = Output.concat("storage.googleapis.com/", bucket.id)
print(destination)
This returns the same <pulumi.output.Output object at 0x10c39ae80>
instead of the expected string.
Any suggestions would be appreciated.
You can't print an Output
because an output is a container for a deferred value that is not yet available when print
is called. Instead, try exporting the value as a stack output
pulumi.export("destination", destination)
If you really want to print it, try doing so from within an apply
:
destination.apply(lambda v: print(v))
By the way, your first snippet can be simplified to
destination = bucket.id.apply(lambda id: f"storage.googleapis.com/{id}")
but concat
is even simpler indeed.