man7-training
man7-training copied to clipboard
Terraform set up VMs for man7.org training
trafficstars
Terraform
This repository sets up Virtual Machines in Google Cloud Platform for man7.org training. This terraform module will output
- Private key (RSA PEM encoded) for the user account (default username
tux). - Password for the user account (default username
tux). - SSH commands via key and password.
- SSH command to access Serial Console. This is needed to access GRUB menu or debug VM at boot time if needed.
- Saves the Terraform state file in a bucket in your project.
- A wrapper shell script
./tf.shwhich automatically downloads Terraform binary and sets up your environment etc. - Updates GRUB config for the machine.
- Installs all the relevant tools (Ubuntu only).
Setup
- Create a new project in GCP or use an existing one. Note down the Project ID and update the variable
project-idin./variables.tf. You may need to enable Compute Engine API if you are creating a new project. - Create a bucket with a unique name and update
backend.tfvariablebucket. This is because backend definition does not allow interpolation. :( - Create a service account with
EditorandOwnerpermissions for Terraform. Default name for the account isterraform. - Create a key pair for the above service account and save it in
./credentials/key.json. - Also, save the key inside the heredoc in
./credentials/secret.auto.tfvarsby pasting the JSON document between theEOFs heredoc.
GRUB menu access
Use the private RSA key and the serial console command to SSH into serial console in a separate terminal window.
Rebooting Virtual Machine and immediately switching to the serial console and pressiing SHIFT key will get you GRUB menu.
Before the 1st use
$ ./tf.sh init
Commands
Graph
$ ./tf.sh graph | dot -Tpng > graph.png
Plan
$ /tf.sh plan
Apply
$ ./tf.sh apply