首页 > 解决方案 > 谷歌部署管理器使用 --properties 参数访问嵌套属性

问题描述

如果我使用 jinja 模板,我可以通过命令行覆盖属性,如下所示:

--properties zone:us-central1-a,machineType:n1-standard-1,image:debian-9

但是我没有看到使用标签或 environmentVariables 等嵌套属性执行此操作的文档或示例,例如:

resources:
  - name: resource-name
    type: 'gcp-types/cloudfunctions-v1:projects.locations.functions'
    properties:
      labels:
        testlabel1: testlabel1value
        testlabel2: testlabel2value
      environmentVariables:
        TEST: 'zzzzzzzzz'

如何设置这样的属性?这不起作用:--properties labels:testlabel1:newvalue

标签: google-deployment-manager

解决方案


这里的简短回答是,该--properties标志并不意味着将属性值传递给模板。模板不能在没有配置文件的情况下运行,--properties 标志旨在替换配置文件。您传递的每个参数都与在配置文件中列出它们相同。

本质上 using--template my-template.py --properties zone:us-central1-f相当于运行--config myConfig.yamlYAML 定义如下:

进口:
- 路径:我的模板.py

资源:
- 名称:一些资源
  类型:my-temaplte.py
  特性:
    区域:us-central1-f

--properties标志并不意味着传递原始数据来替换非变量。

尽管这不能直接回答您的问题,但您通常不需要在标志中定义嵌套值。您的模板通常会调用从对象中获取的直接变量properties

尽管如此,我还是尝试了一些测试,据我所知,你不能这样做。


推荐阅读