Giter VIP home page Giter VIP logo

gcloud-vm-toggle's Introduction

gcloud-vm-toggle

Simple script to toggle up/down a VM instance in Google Cloud Compute Engine.

Motivation

I've recently set up a VSCode server in a Compute Engine instance using the amazing code-server project and it's great! It's really cool to have access to a performant, custom development environment wherever I am :D

Buuuut, I'm obviously not using it at all times, so keeping it running 24/7 would be a waste of resources and ultimately money: I needed some way to turn it off when I'm not using it. So I made this.

There are probably better/cooler solutions but I just wanted something quick and simple to start/stop the VM. Now, I can turn on/off the server with just a command! I don't know about you but I call that M A G I C ๐ŸŽฉ๐Ÿ‡โœจ

Requirements

  • Node.js installed. I've tested it v12 LTS so I guess you should use that at least (?)
  • An instance you want to turn on/off in Google Cloud Compute Engine as the name of the project suggests ๐Ÿ˜…

Quick start

  1. Clone the project somewhere
  2. Create a Google Cloud Service Account Key. It must have write access to Compute Engine resources.
  3. Create a .env file based on the provided .env.example.
  4. (Optional) Create an alias in your .zshrc, .bashrc or similar file:
alias codeup=`node /path-to-the-project/index.js up`
alias codedown=`node /path-to-the-project/index.js down`
alias codetgl=`node /path-to-the-project/index.js`

Usage

node index.js [up|down]

  • up: starts the machine and pings until it's reachable
  • down: stops the machine
  • When called with no arguments, it will check the current status and toggle it (i.e. RUNNING -> stop, TERMINATED -> start)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.