[英]How do I retrieve property a of Pulumi resource using python?
I'm creating a GCP storage bucket and aggregated log sink using Pulumi and Python.我正在使用 Pulumi 和 Python 创建 GCP 存储桶和聚合日志接收器。 To create the sink I need the value of the bucket id from Pulumi.
要创建接收器,我需要来自 Pulumi 的存储桶 ID 的值。
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"
.我希望得到类似于
"storage.googleapis.com/bucket_id"
的目标变量的打印输出。 Instead I am getting <pulumi.output.Output object at 0x10c39ae80>
.相反,我
<pulumi.output.Output object at 0x10c39ae80>
得到<pulumi.output.Output object at 0x10c39ae80>
。 I've also tried using the Pulumi concat method as described at the Pulumi docs .我也尝试过使用Pulumi 文档中描述的 Pulumi concat 方法。
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.这将返回相同的
<pulumi.output.Output object at 0x10c39ae80>
而不是预期的字符串。
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.您无法打印
Output
因为输出是延迟值的容器,在调用print
时该值尚不可用。 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
:如果您真的想打印它,请尝试从
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.但
concat
确实更简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.