1
votes

I'm trying to deploy a Custom Instance Template using gcloud deployment-manager, but I keep getting this error:

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"}}'

My python generate_config function is this:

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}

Properties is not empty, so the error message doesn't make much sense. Any ideas?

Thx!

1

1 Answers

1
votes

After reading this example, I just found that the correct structure for compute.v1.instanceTemplate is:

  ...
  'type': 'compute.v1.instanceTemplate',
  'name': 'worker-template',
  'properties': {
      'project': 'my-project',
      'properties': {
           'zone': context.properties['zone'],
           ...
      }
  }
  ...

The structure follows this doc