- Motivation: As Data Engineer that lived in third world with low income, I continue finding it difficult to upgrade Computer hardware as result of tools in my chosen carrier. So in order to solve this problem , I look into cloud enviroment and GCP come to rescue by giving $300 to every new gmail
- WHY would anyone use this resource!,
- Ok, your Computer hardware comes preinstalled with 32GB RAM with core i9, but you need computing power of let say 64GB of RAM vCPU 32 to crunching data or perform highly memory or CPU intensive computing calculation
- You are on low budget limited data plan or even slow download speed, you got tens of docker image to be dowload for your data pipeline or You are are building couple of docker images locaaly that need to be upload to either private/public registry, this resource will make sure everything is done smoothly in the remote machine.
- You just need a "disposable" computing environment, once you are done, you want it to be shut-down even if you are having cup of coffee in Bahamas beach.
- Cloud resource can quicly sky-rocket if not well managed, you want a self-disposable compute instance that does not dig hole in your financial pocket, then you will need this resource.
- lastly, everything is automate, just supply few parameter, you are good to go!
- A Google Account to access GCE (create new account ($300 free credit is avaialable for your usage or use existing GCP account with billing active)
- create GCP project
- create Service account and generate json file (see below instruction)
- Terraform installed on your local computer
- Create Terraform Cloud Account to integrate into Github Action. See instruction below
- Fork or clone this repo
https://github.com/blueband/Remote_WKstation.git - Github Action
- Create GCS bucket named
tf-tfstatefile
GCS_TERRAFORM_GITHUB_SASee below on how to format the json file for thright output supported by GA Secret vaultSECRET_KEY_SSH(optional, if you want to setup SSH KEY, on the Remoste Workstation, Not Implemetent at Moment, See # TODO Section 3.TF_API_TOKEN: To be generate from Terraform Cloud Account Read here on how to go about itTF_PROJECTID: GCP project ID, in which the resource will be createZONE: GCP zone in which the resource will be create
Note: Terraform Cloud works ONLY with *.auto.tfvars file (terraform.tfvars will be ignore)
wkstation_boot_disk_size_gb: Compute Hardisk sizewkstation_machine_type: Highly recommeded for change but dependend on your computing need. See below formachine_typetags for GCP computeos_image: Operating Software (default is "ubuntu-os-cloud/ubuntu-2110")desired_status= "RUNNING" # Manual methods of shut-down VM from Terraform. optional can either take RUNNING or TERMINATED values.machine_name: change this to unique name (all symbol except '-' and English alphabets are not accept)disk_type: default is "pd-ssd"wk_stop_update_status: default is true # To take advantage of upgradable machine type on GCP
- clone or fork this repo
https://github.com/blueband/Remote_WKstation.git - Edit
*.auto.tfvarsfile See above CHANGEABLE VARIABLE - create bucket named
tf-tfstatefileif you haven't - create secret in Github Action with name matching ENVIRONMENT VARIABLE listed above. Please, Github Action , Secret are repo based, So you will to create a repo on your Gihtub, push the files to it, then follow instruction on how to setub Secret in GA in the link below
- Setup API in Terraform Cloud See instruction below
- Once, all parameter above are setup, push the code into a staging branch in your repo created earlier (name it whatever, I used
dev) - Raise PR to
mainbranch from your staging branch, this will triggerterraform planstage, see it underActiontab in the current repo - If everything went smoothly, you can then
mergeand this will triggeredterraform applystage, whch will create VM in your GCP account
BONUS: There exist in-built script that monitor resources usage on the created VM, once resource usage threshold is below 10% threshold, the Remote workstation will shut down gracefully and save you of unneaccesary bills from Google.
Hope you like this !
Local Machine OS: ubuntu
- Create SSH KEY, if you have not create one before, follow instruction here https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html
- After step above, copythe output of this command
cat ~/.ssh/{"name_use_above.pub"}# replace {"name_use_above.pub"} with name of your public key as found atls ~/.ssh/ - In GCP console, Go to Compute Engine → Metadata, Select SSH tab, click Edit button, Then just edit or add your SSH key there.
- Go back to the VM dashboard, grab your machine Public IP
- On Your VSCODE IDE, click on
View, thenCommand paltetethen typesshin the prompt, look forOpen SSh Configuration fileand click on it, then click on~/.ssh/config - Enter the following
-
Host NAME_OF_YOUR_CHOICE HostName IP_OF_REMOTE_MACHINE_COPY_AT_STEP_4_ABOVE User YOUR_LOCAL_USERNAME_NOT ROOT IdentityFile ~/.ssh/PRIVATE_KEY_FILE # IT DOES NOT HAVE ".PUB" EXTENTION IdentitiesOnly yes - Once above parameteer are replace accordingly, we can test access to the remote machine by
- from Terminal issues the following command 1
ssh NAME_OF_YOUR_CHOICENOTE: NAME_OF_YOUR_CHOICE is the name we defile in the file above if everything is fine, we will be able to login into the Remote workstation - From VSCODE, go to
View->Command paltete->Connect to Hostclick on the name specified above when we edit config file. If everything is setup correctly, VSCODe will connect to the remote machine and all your works, developmet will be save on the remote machine. Everything you do locally on VSCODE can now be doneon the Remote Workstation.
- from Terminal issues the following command 1
- Adding Local machine public SSH-KEY to the remote machine via GA
- Ability to create more than one VM (POC)
- Terraform cloud
- Github Action
- https://gcpinstances.doit-intl.com/ View GCP machine_type, price, RAM, vCPU
- Shut Down Script : https://gist.githubusercontent.com/justinshenk/312b5e0ab7acc3b116f7bf3b6d888fa4/raw/59f021c2bf0388ba36e5a589dba52e233ee84964/idle-shutdown.sh
- https://medium.com/analytics-vidhya/how-to-auto-shutdown-an-idle-vm-instance-on-gcp-to-cut-fat-bills-b08ae20437af