我尝试使用gcloud deployment-manager部署自定义实例模板,但我一直收到此错误:
ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1507833758152-55b5de788f540-e3be8bf6-a792d98e]: errors: - code: RESOURCE_ERROR location: /deployments/my-project/resources/worker-template message: '{"ResourceType":"compute.v1.instanceTemplate","ResourceErrorCode":"400","ResourceErrorMessage":{"code":400,"errors":[{"domain":"global","message":"Invalid value for field ''resource.properties'': ''''. Instance Templates must provide instance properties.","reason":"invalid"}],"message":"Invalid value for field ''resource.properties'': ''''. Instance Templates must provide instance properties.","statusMessage":"Bad Request","requestPath":"https://www.googleapis.com/compute/v1/projects/my-project/global/instanceTemplates","httpMethod":"POST"}}'
我的python generate_config函数是这样的:
def generate_config(context): resources = [{ 'type': 'compute.v1.instanceTemplate', 'name': 'worker-template', 'properties': { 'zone': context.properties['zone'], 'description': 'Worker Template', 'machineType': context.properties['machineType'], 'disks': [{ 'deviceName': 'boot', 'type': 'PERSISTENT', 'boot': True, 'autoDelete': True, 'initializeParams': { 'sourceImage': '/'.join([ context.properties['compute_base_url'], 'projects', context.properties['os_project'], 'global/images/family', context.properties['os_project_family'] ]) } }], 'networkInterfaces': [{ 'network': '$(ref.' + context.properties['network'] + '.selfLink)', 'accessConfigs': [{ 'name': 'External NAT', 'type': 'ONE_TO_ONE_NAT' }] }] } }] return {'resources': resources}
属性不为空,因此错误消息没有多大意义。有什么想法吗?
THX!
答案 0 :(得分:1)
阅读this example后,我发现compute.v1.instanceTemplate的正确结构是:
... 'type': 'compute.v1.instanceTemplate', 'name': 'worker-template', 'properties': { 'project': 'my-project', 'properties': { 'zone': context.properties['zone'], ... } } ...
结构遵循this doc