如何覆盖 GCP 部署管理器中的部署包默认设置?

How do I override Deployment package defaults in GCP Deployment Manager?

我想创建一个 WURFL Microservice Basic from the GCP Marketplace 的实例,但是我想以编程方式执行此操作,以便在需要时可以重现它。

我从上面的链接页面下载了部署 zip 文件:

并将其解压缩到我的机器上,所以这里我有创建 WURFL 解决方案的代码:

文件 test_config.yaml 包含有关我的部署的相关信息,我将区域更改为我要部署到的区域:

imports:
- path: wurfl-microservice-basic.jinja

resources:
- name: wurfl-microservice-basic
  type: wurfl-microservice-basic.jinja
  properties:
    zone: europe-west2-a

现在我尝试使用命令进行部署:

gcloud deployment-manager deployments create \
  wurfl \
  --project xxxxxxx \
  --config test_config.yaml

失败并出现错误:

The fingerprint of the deployment is b'EciU4ogM5bd10ff_MnHsVQ==' Waiting for create [operation-1632242107865-5cc83fb06da45-f22cec62-c9ce6955]...failed.

ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1632242107865-5cc83fb06da45-f22cec62-c9ce6955]: errors:

  • code: RESOURCE_ERROR location: /deployments/wurfl/resources/wurfl-vm message: "{"ResourceType":"compute.v1.instance","ResourceErrorCode":"400"
    ,"ResourceErrorMessage":{"code":400,"errors":[{"domain":"global","
    message":"Invalid value for field 'resource.networkInterfaces[0].network': 'https://www.googleapis.com/compute/v1/projects/xxxxxxx/global/networks/default'.
    \ The referenced network resource cannot be found.","reason":"invalid"}],"
    message":"Invalid value for field 'resource.networkInterfaces[0].network': 'https://www.googleapis.com/compute/v1/projects/xxxxxxx/global/networks/default'.
    \ The referenced network resource cannot be found.","statusMessage":"Bad Request"
    ,"requestPath":"https://compute.googleapis.com/compute/v1/projects/xxxxxxx/zones/europe-west2-a/instances"
    ,"httpMethod":"POST"}}"

(请注意,根据我的更改,它在最后一行中正确引用了 europe-west2

这个错误是有道理的,这个项目没有默认网络,它有一个我创建的备用网络,我想覆盖网络的默认设置,但我不知道该怎么做。

vm_instance.py.schema 中,我可以看到网络是在 yaml 列表中定义的,如下所示:

  networks:
    description: List of Networks for each network interface of this VM
    type: array
    default:
    - default

所以我尝试以与设置区域类似的方式更改网络:

imports:
- path: wurfl-microservice-basic.jinja

resources:
- name: wurfl-microservice-basic
  type: wurfl-microservice-basic.jinja
  properties:
    zone: europe-west2-a
    networks:
      - mynetwork

但这导致了同样的错误。我还尝试使用正确的网络名称修改 vm_instance.py.schema,但这也没有任何影响。

有人可以告诉我如何覆盖默认值(在本例中是网络)以便我可以部署它吗?

我明白了,这就是要求的

imports:
- path: wurfl-microservice-basic.jinja

resources:
- name: wurfl-microservice-basic
  type: wurfl-microservice-basic.jinja
  properties:
    zone: europe-west2-a
    network: mynetwork
    subnetwork: mysubnetwork