Files
weave-scope/provisioning/gcp
Daniel Holbach 37ea4937a4 Squashed 'tools/' changes from f041a74ff..604e133c2
604e133c2 Merge pull request #167 from weaveworks/update-scheduler-instructions
bdd647e92 Merge pull request #169 from weaveworks/go-1.14.4
2c2792e7d Upgrade to Go 1.14.4
e6dd5e8f0 Merge pull request #168 from weaveworks/downgrade-werkzeug
144aa64c0 Restruct scheduler to use compatible version of werkzeug library
cc807901d Update instructions on how to deploy gc/scheduler
51a217660 Merge pull request #166 from weaveworks/165-rename-circleci-to-wksctl
bfd7a2bbe Renames circleci project wks -> wksctl afte code move
a5f7be3cc Note that the API token was revoked
15e4cfb94 Merge pull request #164 from weaveworks/improve-lint
dc8722589 Fix lint errors in Python code
8cb6a62a2 Set failure state if lint_files fails
c635ce412 Simplify the no-arguments case
167b7ed57 Skip entire directories that match filter patterns
1caa455a6 Refactor: read filter patterns once at start
4cc7911e5 Merge pull request #163 from weaveworks/fix-lint
393808dab Merge pull request #162 from weaveworks/golang-python3
3c5fcd16e Make lint run on CircleCI
f0936a1e9 lint all directories if not given a list
68f62a393 Fix typo in lint script
9ef44b057 Stop installing promtool
882df5ec5 Install python 3 instead of obsolete v2.7
988002377 Update Go to latest 1.13.3
2a2df5278 Merge pull request #161 from murali-reddy/terraform-update
bf8ed23b9 update google_compute_instance arguments as per the latest documentation

git-subtree-dir: tools
git-subtree-split: 604e133c2b7eb805766eab7be28723ef1ccd32aa
2020-09-03 10:15:13 +02:00
..

Google Cloud Platform

Introduction

This project allows you to get hold of some machine on Google Cloud Platform. You can then use these machines as is or run various Ansible playbooks from ../config_management to set up Weave Net, Kubernetes, etc.

Setup

  • Log in console.cloud.google.com with your Google account.

  • Go to API Manager > Credentials > Create credentials > Service account key, in Service account, select Compute Engine default service account, in Key type, select JSON, and then click Create.

  • This will download a JSON file to your machine. Place this file wherever you want and then create the following environment variables:

$ export GOOGLE_CREDENTIALS_FILE="path/to/your.json"
$ export GOOGLE_CREDENTIALS=$(cat "$GOOGLE_CREDENTIALS_FILE")
  • Go to Compute Engine > Metadata > SSH keys and add your username and SSH public key; or set it up using gcloud compute project-info add-metadata --metadata-from-file sshKeys=~/.ssh/id_rsa.pub. If you used your default SSH key (i.e. ~/.ssh/id_rsa.pub), then you do not have anything to do. Otherwise, you will have to either define the below environment variable:
$ export TF_VAR_gcp_public_key_path=<path to your SSH public key>
$ export TF_VAR_gcp_private_key_path=<path to your SSH private key>

or to pass these as Terraform variables:

$ terraform <command> \
-var 'gcp_public_key_path=<path to your SSH public key>' \
-var 'gcp_private_key_path=<path to your SSH private key>'
  • Set the username in your public key as an environment variable. This will be used as the username of the Linux account created on the machine, which you will need to SSH into it later on.

    N.B.:

    • GCP already has the username set from the SSH public key you uploaded in the previous step.
    • If your username is an email address, e.g. name@domain.com, then GCP uses name as the username.
export TF_VAR_gcp_username=<your SSH public key username>
  • Set your current IP address as an environment variable:
export TF_VAR_client_ip=$(curl -s -X GET http://checkip.amazonaws.com/)

or pass it as a Terraform variable:

$ terraform <command> -var 'client_ip=$(curl -s -X GET http://checkip.amazonaws.com/)'
  • Set your project as an environment variable:
export TF_VAR_gcp_project=weave-net-tests

or pass it as a Terraform variable:

$ terraform <command> -var 'gcp_project=weave-net-tests'

Bash aliases

You can set the above variables temporarily in your current shell, permanently in your ~/.bashrc file, or define aliases to activate/deactivate them at will with one single command by adding the below to your ~/.bashrc file:

function _gcp_on() {
  export GOOGLE_CREDENTIALS_FILE="<path/to/your/json/credentials/file.json"
  export GOOGLE_CREDENTIALS=$(cat "$GOOGLE_CREDENTIALS_FILE")
  export TF_VAR_gcp_private_key_path="$HOME/.ssh/id_rsa"     # Replace with appropriate value.
  export TF_VAR_gcp_public_key_path="$HOME/.ssh/id_rsa.pub"  # Replace with appropriate value.
  export TF_VAR_gcp_username=$(cat "$TF_VAR_gcp_public_key_path" | cut -d' ' -f3 | cut -d'@' -f1)
}
alias _gcp_on='_gcp_on'
function _gcp_off() {
  unset GOOGLE_CREDENTIALS_FILE
  unset GOOGLE_CREDENTIALS
  unset TF_VAR_gcp_private_key_path
  unset TF_VAR_gcp_public_key_path
  unset TF_VAR_gcp_username
}

N.B.:

  • sourcing ../setup.sh defines aliases called gcp_on and gcp_off, similarly to the above (however, notice no _ in front of the name, as opposed to the ones above);
  • ../setup.sh's gcp_on alias needs the SECRET_KEY environment variable to be set in order to decrypt sensitive information.

Usage

  • Create the machine: terraform apply
  • Show the machine's status: terraform show
  • Stop and destroy the machine: terraform destroy
  • SSH into the newly-created machine:
$ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no `terraform output username`@`terraform output public_ips`

or

source ../setup.sh
tf_ssh 1  # Or the nth machine, if multiple VMs are provisioned.

Resources