Skip to content

Instantly share code, notes, and snippets.

@fhinkel
Last active May 24, 2018 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhinkel/422392439229630690975a62e9f1e534 to your computer and use it in GitHub Desktop.
Save fhinkel/422392439229630690975a62e9f1e534 to your computer and use it in GitHub Desktop.
Create minimal Compute Engine instance with Node.js
// Run `npm install @google-cloud/compute` first.
const Compute = require('@google-cloud/compute');
const compute = new Compute();
// Creates a new VM using the latest Ubuntu image.
(async () => {
try {
const zone = await compute.zone('us-central1-a');
const data = await zone.createVM(
'ubuntu-instance',
{ os: 'ubuntu' }
);
const operation = data[1];
await operation.promise();
// Virtual machine created.
} catch (error) {
console.error(error);
}
})();
@fhinkel
Copy link
Author

fhinkel commented May 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment