You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Deployment Manager引用未按预期工作,求排查方案

问题描述

为学习Google Deployment Manager的模板引用与输出功能,编写了极简配置示例:

  • 低阶模板bucket.jinja:创建动态命名的Cloud Storage桶,并输出outValue变量。
  • 高阶配置config.yaml:导入bucket.jinja,创建多个资源,其中softcoded-3尝试引用softcoded-1的outValue作为属性值,并设置dependsOn依赖。

执行部署预览时出现错误:Referenced resource softcoded-1 could not be found,移除softcoded-3后部署正常。预期softcoded-3能创建名为templated-out-testbucket的桶,需解决该问题。


相关代码

bucket.jinja

{% set NAME = properties['name'] %}

resources:
  - name: templated-{{ NAME }}
    type: storage.v1.bucket
    properties:
      location: us-central1
      kind: storage#bucket
      storageClass: STANDARD
      versioning:
        enabled: false

outputs:
  - name: outValue
    value: out-{{ NAME }}

原错误版本config.yaml

imports:
  - path: bucket.jinja

resources:
  - name: softcoded-1
    type: bucket.jinja
    properties:
      name: testbucket

  - name: hardcoded-$(ref.softcoded-1.outValue)
    type: storage.v1.bucket
    properties:
      location: us-central1
      kind: storage#bucket
      storageClass: STANDARD
      versioning:
        enabled: false

  - name: softcoded-2
    type: bucket.jinja
    properties:
      name: noref
    metadata:
      dependsOn:
        - softcoded-1

  - name: softcoded-3
    type: bucket.jinja
    properties:
      name: $(ref.softcoded-1.outValue)
    metadata:
      dependsOn:
        - softcoded-1

错误信息

% gcloud --project myproject deployment-manager deployments update test-deploy --config config.yaml --preview
The fingerprint of the deployment is b'5Hesgz1ujBJIotnjwJHJsg=='
Waiting for update [operation-1709425554385-612b6a6f06adf-8d791850-cffb5f4a]...failed.                                                                         
ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1709425554385-612b6a6f06adf-8d791850-cffb5f4a]: errors:
- code: CONDITION_NOT_MET
  message: Referenced resource softcoded-1 could not be found. In 'finalValue' section
    of 'outputs' in the manifest layout.

问题原因与解决方法

问题原因

错误使用了引用语法:$(ref)仅用于引用GCP原生资源(如Cloud Storage桶、虚拟机等)的属性,而softcoded-1是Deployment Manager的模板实例资源,其输出值需要通过$(outputs)语法来引用。

解决方法

将config.yaml中所有引用模板输出的部分,把$(ref.softcoded-1.outValue)替换为$(outputs.softcoded-1.outValue)即可。

修正后的config.yaml

imports:
  - path: bucket.jinja

resources:
  - name: softcoded-1
    type: bucket.jinja
    properties:
      name: testbucket

  - name: hardcoded-$(outputs.softcoded-1.outValue)
    type: storage.v1.bucket
    properties:
      location: us-central1
      kind: storage#bucket
      storageClass: STANDARD
      versioning:
        enabled: false

  - name: softcoded-2
    type: bucket.jinja
    properties:
      name: noref
    metadata:
      dependsOn:
        - softcoded-1

  - name: softcoded-3
    type: bucket.jinja
    properties:
      name: $(outputs.softcoded-1.outValue)
    metadata:
      dependsOn:
        - softcoded-1

补充说明

  • $(outputs.<模板实例名>.<输出名>)是引用Deployment Manager模板输出的标准语法,会自动处理资源依赖关系,确保softcoded-1的输出值生成后再被softcoded-3使用。
  • 保留dependsOn配置不会产生冲突,也可以选择移除,因为$(outputs)会隐式添加依赖。

内容的提问来源于stack exchange,提问作者seawolf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 14:23:18