Skip to content

Instantly share code, notes, and snippets.

@ismailbaskin
Created December 8, 2018 21:06
Show Gist options
  • Save ismailbaskin/39d0dad826d908d238cc24f0285d61da to your computer and use it in GitHub Desktop.
Save ismailbaskin/39d0dad826d908d238cc24f0285d61da to your computer and use it in GitHub Desktop.
Shutdown GCP VMs
const Compute = require('@google-cloud/compute');
const compute = new Compute();
exports.stopPolicy = async () => {
const [vms] = await compute.getVMs({
filter: `labels.stop-policy:workhour`
});
await Promise.all( vms.map(vm => vm.stop()) );
console.log(`${vms.length} VM(s) stopped!`)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment