[英]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.output.Output object at 0x10c39ae80>
。 我也嘗試過使用Pulumi 文檔中描述的 Pulumi concat 方法。
destination = Output.concat("storage.googleapis.com/", bucket.id)
print(destination)
這將返回相同的<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
確實更簡單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.