使用 Deployment Manager 创建 compute.v1.instanceTemplate 时出现神秘的缺失字段错误

使用 Deployment Manager 创建 compute.v1.instanceTemplate 时出现神秘的缺失字段错误

我正在尝试使用部署管理器(v2)创建一个compute.v1.instanceTemplate,但是出现以下错误:

Unexpected response from resource of type compute.v1.instanceTemplate: 400 {statusMessage=Bad Request, errors=[{message=Invalid value for field 'resource.properties': ''.  Instance Templates must provide instance properties., domain=global, reason=invalid}]}

我猜它抱怨缺少某个属性,但我无论如何也想不出是哪一个。我查看了实例模板资源和高级部署 例子,而我没有似乎遗漏了什么。不过,我很高兴被证明是错的。

以下是通过 获取的完整资源gcloud deployment-manager deployments describe --log-http name

{
 "id": "redacted",
 "insertTime": "2015-10-03T05:13:33.325-07:00",
 "updateTime": "2015-10-03T05:42:50.152-07:00",
 "name": "tpl-redacted",
 "type": "compute.v1.instanceTemplate",
 "update": {
  "manifest": "https://www.googleapis.com/deploymentmanager/v2/projects/project-redacted/global/deployments/redacted/manifests/manifest-redacted",
  "error": {
   "errors": [
    {
     "code": "RESOURCE_ERROR",
     "location": "redacted/tpl-redacted",
     "message": "Unexpected response from resource of type compute.v1.instanceTemplate: 400 {statusMessage=Bad Request, errors=[{message=Invalid value for field 'resource.properties': ''.  Instance Templates must provide instance properties., domain=global, reason=invalid}]}"
    }
   ]
  },
  "state": "FAILED",
  "intent": "CREATE_OR_ACQUIRE",
  "properties": "canIpForward: true\ndisks:\n- autoDelete: true\n  boot: true\n  deviceName: boot\n  initializeParams:\n    diskSizeGb: 10\n    diskType: pd-standard\n    sourceImage: https://www.googleapis.com/compute/v1/projects/project-redacted/global/images/redacted-image\n  mode: READ_WRITE\n  type: PERSISTENT\nmachineType: https://www.googleapis.com/compute/v1/projects/project-redacted/zones/asia-east1-c/machineTypes/g1-small\nnetworkInterfaces:\n- accessConfigs: []\n  network: $(ref.nw-redacted.selfLink)\nscheduling:\n  automaticRestart: true\n  onHostMaintenance: MIGRATE\nserviceAccounts:\n- scopes:\n  - storage-ro\ntags:\n  items:\n  - redacted\nzone: asia-east1-c\n",
  "finalProperties": "canIpForward: true\ndisks:\n- autoDelete: true\n  boot: true\n  deviceName: boot\n  initializeParams:\n    diskSizeGb: 10\n    diskType: pd-standard\n    sourceImage: https://www.googleapis.com/compute/v1/projects/project-redacted/global/images/redacted-image\n  mode: READ_WRITE\n  type: PERSISTENT\nmachineType: https://www.googleapis.com/compute/v1/projects/project-redacted/zones/asia-east1-c/machineTypes/g1-small\nnetworkInterfaces:\n- accessConfigs: []\n  network: https://www.googleapis.com/compute/v1/projects/project-redacted/global/networks/nw-redacted\nscheduling:\n  automaticRestart: true\n  onHostMaintenance: MIGRATE\nserviceAccounts:\n- scopes:\n  - storage-ro\ntags:\n  items:\n  - redacted\nzone: asia-east1-c\n"
 }
}

下面是一个更加人性化的版本finalProperties

canIpForward: true
disks:
- autoDelete: true
  boot: true
  deviceName: boot
  initializeParams:
    diskSizeGb: 10
    diskType: pd-standard
    sourceImage: https://www.googleapis.com/compute/v1/projects/project-redacted/global/images/redacted-image
  mode: READ_WRITE
  type: PERSISTENT
machineType: https://www.googleapis.com/compute/v1/projects/project-redacted/zones/asia-east1-c/machineTypes/g1-small
networkInterfaces:
- accessConfigs: []
  network: https://www.googleapis.com/compute/v1/projects/project-redacted/global/networks/nw-redacted
scheduling:
  automaticRestart: true
  onHostMaintenance: MIGRATE
serviceAccounts:
- scopes:
  - storage-ro
tags:
  items:
  - redacted
zone: asia-east1-c

有什么想法吗?或者,如果能提供成功compute.v1.instanceTemplate部署的示例,我们将不胜感激。

答案1

事实证明,其中一个高级部署示例确实有一个compute.v1.instanceTemplate 使用示例zone。资源应该指定一个,而不是一个project,这确实更有意义,尽管除了这个例子之外,似乎没有任何地方记录这一点。然而,不太合理的是,实际的instanceTemplate参数放在里面其他properties 对象。不确定这是从哪里来的,但这是我最终工作的 jinja 模板(请注意,一些字段正在使用其默认值,实际上可以省略):

resources:
  - name: {{ env["name"] }}
    type: compute.v1.instanceTemplate
    properties:
      project: {{ env["project"] }}
      properties:
        machineType: {{ properties["machineType"] }}
        canIpForward: true
        scheduling:
          automaticRestart: true
          onHostMaintenance: MIGRATE
          preemptible: false
        tags:
          items:
            - redacted
        disks:
          - deviceName: boot
            boot: true
            autoDelete: true
            mode: READ_WRITE
            type: PERSISTENT
            initializeParams:
              diskSizeGb: 10
              diskType: pd-standard
              sourceImage: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/images/redacted
        networkInterfaces:
          - network: $(ref.{{ properties["network"] }}.selfLink)
        serviceAccounts:
          - email: default
            scopes:
              - https://www.googleapis.com/auth/devstorage.read_only

相关内容