You can never find enough of these tutorials/examples lying around, so here's one in golang borrowing heavily from google's own examples.
- Navigate to the IAM & admin" section of your project and select "Service Accounts"
- Create a new Account including the roles "Compute Admin" & "Service Account User"
- Ask for a new private key for download in JSON format
- In the downloaded JSON file, you'll see "client_email" & "private_key"
$ export GCE_EMAIL=<client_email value>
$ export GCE_PRIVATE_KEY='<private_key value>'
- keep in mind that some deploy services (looking at you, CircleCI) add these behind the scenes (meaning double single quotes and an incorrect key)
- This sample file launches an f1-micro instance named 'bluesbros2', running CoreOS in us-east-1 within my project
- Please adjust to your needs ;)
- Here's the list of OS images
- us-east-1 & f1-micro is special because you basically get one freebie / month!
- Before launching, you can add your own SSH keys (you'll always have console access from Google's embedded TTY)
- Every instance launched in your project will be accessible via the users/keys you setup here
- For even finer control of the Google Cloud offerings, consider downloading their
gcloud
tool (MacOS) - Then you can run cmds like:
gcloud auth login
gcloud config set project <your projectID>
gcloud compute instances list
gcloud compute instances describe <your instance name> --format json
- simply executing
go run main.go
will launch your instance