I have a node server which handles gcp instance operations. I am trying to update the machine type of a existing running instance. I don't want to update any other properties like disk size or anything.
const computeClient = new Compute.InstancesClient({
projectId: "project",
keyFilename: "keyfile",
});
let resource = {
instance: "testinstance",
instanceResource: {
machineType : "zones/us-central1-a/machineTypes/e2-standard-4",
name: "testinstance"
},
project: "project",
zone : "us-central1-a"
}
const resp1 = await computeClient.update(resource);
When I try to run above code this error occurs
Stacktrace:
====================
Error: Invalid value for field 'resource.disks': ''. No disks are specified.
at Function.parseHttpError (////node_modules/google-gax/build/src/googleError.js:49:37)
at decodeResponse (///node_modules/google-gax/build/src/fallbackRest.js:72:49)
at ////node_modules/google-gax/build/src/fallbackServiceStub.js:90:42
at processTicksAndRejections (node:internal/process/task_queues:96:5)
node version : v16.14.0
@google-cloud/compute version : 3.1.2
Any solution ? Any code sample to update machine type ?
If you only want to update your instance's machine type you should use the
setMachineTypemethod directly which is meant for this specifically. See example below:Note that machine type can only be changed on a
TERMINATEDinstance as documented here. You'll need to first ensure the instance is stopped or stop it in your code prior to updating machine type. More details on available methods here.