Skip to content

GCE create VM via gcloud npm module

Chakradhar Rao Jonagam edited this page May 5, 2016 · 5 revisions

create a auth json file gcloud-node2test.json by following steps mentioned here https://github.com/GoogleCloudPlatform/gcloud-node

export GCLOUD_PROJECT='yourprojectid'

var projectId = process.env.GCLOUD_PROJECT; 
var gcloud = require('gcloud')({
  projectId: projectId,
  keyFilename: './gcloud-node2test.json'
});
var gce = gcloud.compute({projectId: projectId});
var zone = gce.zone('us-central1-a');
var name = 'ubuntu-http';

zone.createVM(name, { os: 'ubuntu' }, function(err, vm, operation) {
  console.log(err,vm);
  operation.onComplete(function(err, metadata) {
    if (!err) {
      // Virtual machine created!
    }
  });
});
Clone this wiki locally