This repo contains terraform resource templates for quickly setting up virtual machines and other OS instances.
These templates come from the excellant Youtuber The Digital Life from this video.
The original repo is also from The Digital Life and can be found here.
This guide assumes there is a Virtual Machine image on Proxmox called ubuntu-server-jammy
already present. Either create this using packer or manually create it using Proxmox.
This repo also contains my SSH Pub key in
full-clone.tf
, make sure to change this to one that you own
Start by adding the Hashicorp private repo:
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
Next update the apt cache:
sudo apt update
Finally install Terraform:
sudo apt install terraform
Assuming you are in the root directory (terraform/
) of this project, initialise terraform to install all the required providers:
terraform init
Edit credentials.tfvars
to match your Proxmox instance
Run the following to test the template you have created to ensure everything is ok before applying:
terraform plan -var-file=credentials.tfvars
Finally run Terraform to create the requested VM in proxmox:
terraform apply -auto-approve -var-file=credentials.tfvars -replace=proxmox_vm_qemu.control-plane1 -replace=proxmox_vm_qemu.worker-node1 -replace=proxmox_vm_qemu.worker-node2
Note
-replace=proxmox_vm_qemu.control-plane1
is included here to remove the control-plane1 VM if it is currently present on the machine, this can be safely removed if you don't want the existing config to be wiped.
Terraform and Proxmox then takes roughly 1min 40secs to create the Virtual Machine instance.
Note Cloud-Init will also run post terraform install but you can log into the instance while this is going on. Once cloud init is finished, it is recommended to reboot the VM so it can install the latest kernel for that version of Ubuntu.
To destroy the previously created VM instances run the following command:
terraform destroy -target proxmox_vm_qemu.control-plane1 -target proxmox_vm_qemu.worker-node1 -target proxmox_vm_qemu.worker-node2 -var-file=credentials.tfvars