6

I am struggling to create a VM instance using machine image from the REST API.

I can create an instance using 'Try this API' from https://cloud.google.com/compute/docs/reference/rest/beta/instances/insert

{
        "name": 'demo-x2',
        "projects": 'resonant-time-282213',
        "zone" : 'asia-east1-c',
        "sourceMachineImage" : 'projects/resonant-time-282213/global/machineImages/t4-mtml-1',
        "machineType" : 'projects/resonant-time-282213/zones/asia-east1-c/machineTypes/n1-standard-8'
}

While using it inside a python code, it shows the following error in the terminal:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://compute.googleapis.com/compute/v1/projects/resonant-time-282213/zones/asia-east1-c/instances?alt=json returned "Invalid value for field 'resource.disks': ''. No disks are specified.". Details: "Invalid value for field 'resource.disks': ''. No disks are specified.">

Which disk info is it looking for? The disk details are already in the machine image.

chandan
  • 71
  • 1
  • Go to Computer Engine > Machine Image > Click on image name > Create Instance > Bottom of the page has REST request for creating image from machine image. Did you tried with that? – Mahboob Dec 27 '20 at 14:27
  • Yes, I did. It has empty disk:` "disks": [],` and the error to this is: `googleapiclient.errors.HttpError: ` – chandan Dec 27 '20 at 16:13
  • Same problem here. Did you found a solution @chandan ? thks – pksimba Aug 13 '21 at 09:56

1 Answers1

2

It looks like this is only available in the "beta" channel right now.

So when you build your object your have to use "beta" instead of "V1" like this:

service = discovery.build('compute', 'beta', credentials=credentials)