如何使用 python 检索 属性 个 Pulumi 资源?
How do I retrieve property a of Pulumi resource using python?
我正在使用 Pulumi 和 Python 创建 GCP 存储桶和聚合日志接收器。要创建接收器,我需要 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)
我希望得到类似于 "storage.googleapis.com/bucket_id"
的目标变量的打印输出。相反,我越来越
<pulumi.output.Output object at 0x10c39ae80>
。我也尝试过使用 Pulumi docs.
中描述的 Pulumi concat 方法
destination = Output.concat("storage.googleapis.com/", bucket.id)
print(destination)
这 returns 相同 <pulumi.output.Output object at 0x10c39ae80>
而不是预期的字符串。
如有任何建议,我们将不胜感激。
您无法打印 Output
,因为输出是延迟值的容器,在调用 print
时该延迟值尚不可用。相反,尝试将值导出为堆栈输出
pulumi.export("destination", destination)
如果您真的想打印它,请尝试在 apply
:
中打印
destination.apply(lambda v: print(v))
顺便说一下,您的第一个片段可以简化为
destination = bucket.id.apply(lambda id: f"storage.googleapis.com/{id}")
但 concat
确实更简单。
我正在使用 Pulumi 和 Python 创建 GCP 存储桶和聚合日志接收器。要创建接收器,我需要 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)
我希望得到类似于 "storage.googleapis.com/bucket_id"
的目标变量的打印输出。相反,我越来越
<pulumi.output.Output object at 0x10c39ae80>
。我也尝试过使用 Pulumi docs.
destination = Output.concat("storage.googleapis.com/", bucket.id)
print(destination)
这 returns 相同 <pulumi.output.Output object at 0x10c39ae80>
而不是预期的字符串。
如有任何建议,我们将不胜感激。
您无法打印 Output
,因为输出是延迟值的容器,在调用 print
时该延迟值尚不可用。相反,尝试将值导出为堆栈输出
pulumi.export("destination", destination)
如果您真的想打印它,请尝试在 apply
:
destination.apply(lambda v: print(v))
顺便说一下,您的第一个片段可以简化为
destination = bucket.id.apply(lambda id: f"storage.googleapis.com/{id}")
但 concat
确实更简单。