Cha*_*own 2 python google-cloud-platform pulumi
我正在使用 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)
Run Code Online (Sandbox Code Playgroud)
我希望得到类似于 的目标变量的打印输出"storage.googleapis.com/bucket_id"。相反,我得到了
<pulumi.output.Output object at 0x10c39ae80>。我还尝试使用 Pulumi concat 方法,如Pulumi 文档中所述。
destination = Output.concat("storage.googleapis.com/", bucket.id)
print(destination)
Run Code Online (Sandbox Code Playgroud)
这将返回相同的字符串<pulumi.output.Output object at 0x10c39ae80>而不是预期的字符串。
任何建议,将不胜感激。
您无法打印 an Output,因为输出是延迟值的容器,该延迟值在print调用时尚不可用。相反,尝试将值导出为堆栈输出
pulumi.export("destination", destination)
Run Code Online (Sandbox Code Playgroud)
如果您确实想打印它,请尝试在以下位置中执行此操作apply:
destination.apply(lambda v: print(v))
Run Code Online (Sandbox Code Playgroud)
顺便说一句,您的第一个片段可以简化为
destination = bucket.id.apply(lambda id: f"storage.googleapis.com/{id}")
Run Code Online (Sandbox Code Playgroud)
但concat确实更简单。
| 归档时间: |
|
| 查看次数: |
4045 次 |
| 最近记录: |