2

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.

Charles Brown
  • 25
  • 1
  • 3

1 Answers1

6

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.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • Thanks, That makes sense. What I can’t determine is how to build that destination string value as an input to the Organization Sink resource. The destination value is the string storage.googleapis.com/ along wire the bucket I’d. – Charles Brown Nov 01 '20 at 17:25
  • For example, after creating the bucket I'm using ```sink = logging.OrganizationSink("resource-ops-sink", destination=f"storage.googleapis.com/{bucket.id}", filter=filter, org_id=org)``` I'm getting an error on the destination variable ``` gcp:logging:OrganizationSink (resource-ops-sink): error: 1 error occurred: * googleapi: Error 404: Bucket does not exist, notFound ``` – Charles Brown Nov 01 '20 at 19:36
  • 1
    Use `destintion=Output.concat("storage.googleapis.com/", bucket.id)` instead of direct string formatting – Mikhail Shilkov Nov 01 '20 at 19:45