In v1 of my homelab, I created a template VM by booting a Debian image, very carefully doing some manual steps like creating users, setting up disk and swap, installing base packages, etc. I would then clone that template, do more manual steps like adding reconfiguring the timezone, adding SSH keys, regenerating the VM's ssh keys, and setting the hostname.
It's been a long-term goal of mine to move away from this manual and fragile process and leverage modern tooling. I debated moving these steps to Ansible, but I would still have had to set up users and ssh keys, so I ultimately landed on using cloud-init.
This directory holds Terraform cloud for rendering cloud-init templates and creating virtual machines based on those cloud-init configuration files.
Before using this, there needs to be a Proxmox user that has adequate permissions. I followed this guide to create the user.
There also needs to be a template for cloud-init to use. I followed this guide, but used Debian instead of Ubuntu. Searching for " cloud images" will likely lead you to an appropriate cloud image.
- Copy the example files to their expected location. Be sure to replace the real values with the user credentials created above.
$ cp env.example .env $ cp terraform.tfvars.example terraform.tfvars
- Modify
main.tf
to suit your needs. You may also need to pass inusers
to the module since I've defaulted it to my needs inmodules/cloud_init/vars.tf
. You may also want to modifymodules/cloud_init/cloud-init.tfpl
if you want to customize your cloud-init configuration. - Initialize Terraform
$ tf init
- Apply Terraform
You should see Terraform at work and eventually a prompt asking "Do you want to perform these actions?". Enter
$ tf apply
yes
if you want to do so, and watch Terraform create virtual machines that use cloud-init!
- Deploy Proxmox virtual machines using Cloud-init
- cloud-init guide
- Proxmox cloud-init support
- How to deploy Proxmox VMs using Terraform
- @chris2k20/proxmox-cloud-init
- Understanding cloud-init provisioning
- How to create a Proxmox Ubuntu cloud-init image
- Using Terraform and Cloud-Init to deploy and automatically monitor Proxmox instances