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

无法通过Google Cloud Workflows设置VM启动脚本元数据

问题诊断与解决方案

你的问题出在Workflows中setMetadata步骤的items格式错误,导致Compute Engine API虽然返回操作成功,但实际未正确设置元数据。

核心问题

Compute Engine的instances.setMetadata API要求body.items是元数据键值对的数组(即使只设置一个元数据项),但你当前的Workflow配置中直接写了单个key/value对象,没有用数组包裹。API接收请求后认为没有要更新的元数据项,所以返回成功但未做任何修改。

修正后的Workflow配置

将setMetadata步骤的items改为数组格式:

setMetadata:
    call: googleapis.compute.beta.instances.setMetadata
    args:
        instance: ${instance}
        project: ${project}
        zone: ${zone}
        body:
            fingerprint: ${fingerprint}
            items:
                - key: startup-script-url
                  value: gs://<bucket>/startupscript.sh
    result: setMetadataResult

注意这里的items下用-开头,将单个键值对包装成数组元素。

验证步骤

  1. 重新部署修正后的Workflow:
    gcloud workflows deploy <workflow-name> --source=workflow.yaml --region=<your-region>
    
  2. 运行Workflow后,通过控制台或gcloud命令检查VM元数据:
    gcloud compute instances describe workflow-metadata-setting-test --zone=us-central1-c --format="value(metadata.items)"
    
  3. 确认startup-script-url元数据存在后,启动VM,检查存储桶是否生成helloworld.txt文件。

补充说明

  • 为什么API返回成功?因为请求的JSON结构是合法的(包含fingerprint和items字段),但items是无效的非数组格式,API会视为无元数据更新,因此返回完成状态但不修改任何内容。
  • 控制台和gcloud CLI会自动将单个元数据项包装成数组,所以可以正常生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 21:30:25