vm
const compute = require('@google-cloud/compute');
async function createInstance() {
// Lists the available machine types in the specified zone.
const [machineTypes] = await compute.getMachineTypes({
project: 'PROJECT_ID',
zone: 'europe-central2-b',
});
// Create a new instance in the specified project and zone.
const [instance] = await compute.createInstance({
project: 'PROJECT_ID',
zone: 'europe-central2-b',
instanceResource: {
name: 'INSTANCE_NAME',
disks: [
{
initializeParams: {
diskSizeGb: '250',
sourceImage: 'projects/debian-cloud/global/images/family/debian-11',
},
autoDelete: true,
boot: true,
type: 'PERSISTENT',
},
],
machineType: `projects/${'PROJECT_ID'}/zones/${'europe-central2-b'}/machineTypes/${machineTypes[0]}`,
networkInterfaces: [
{
name: 'global/networks/default',
},
],
},
});
console.log(`Instance ${instance.name} created.`);
}