LoginSignup
3
1

More than 3 years have passed since last update.

Node.jsでGCEのインスタンスを作成・削除する

Posted at

作成

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const option = { .......... };
const zone = compute.zone('asia-northeast1-b');
const [vm, operation] = await zone.createVM(vmName, option);
await operation.promise();
console.log(vmName + ' created!');

option の中身はGCPのコンソールでポチポチやった時のパラメータ(下記参照)をコピーして使うと良い

image.png

image.png

削除

const compute = new Compute();
const zone = compute.zone('asia-northeast1-b');
const vm = await zone.vm(vmName);
const [operation] = await vm.delete();
await operation.promise();
console.log(vmName + ' deleted!');
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1