To create a template terraform script that is able to create VMs for a k8s cluster along with an optional VM for NFS. The script also outputs a handy ansible inventory in './ansible/hosts' that can be used to run ansible playbooks after terraform is done creating the VMs.
This repo is using the telmate/proxmox provider for terraform. Refer to the documentation to understand all the variables being used in the 'variables.tf' file.
You need to create a proxmox template for the cloning process. Learn more about proxmox templates here.
If you don't need any modifications on top of your base image, then you can create a new VM that uses an official cloud image from ubuntu, arch, etc and use that VM as a template.
You can also follow one of the guides below to create a modified template:
- My repo for setting up a modified arch linux cloud image using packer
- Telmate's ISO builder
Once this template is ready, the name of the template should go in variable 'CLONE_TEMPLATE' in 'terraform.tfvars' file.
All mandatory variables are put in a file named 'terraform.tfvars'. You can create this file by copying the file 'terraform.tfvars.example' and updating it.
cp terraform.tfvars.example terraform.tfvars
# Edit this file and save it
# Make sure to update CLONE_TEMPLATE as discussed in the previous section
vim terraform.tfvars
Description for all vars in file 'terraform.tfvars' is available in file 'variables.tf'. Apart from the variables mentioned above you can also edit other variables in file 'variables.tf'.
The variables mentioned below are hard-coded in file 'main.tf' as I don't think most people would move away from these defaults. Please update file 'main.tf' if you need different defaults.
<!-- Proxmox TLS check -->
pm_tls_insecure = true
<!-- Full cloning for all VMs -->
full_clone = true
<!-- SSH port for all VMs -->
ansible_port = 22
terraform init
# Make sure the config looks good
terraform plan
terraform apply
This will also create an ansible inventory file in './ansible/hosts'.
This repo is mainly for maintaining a template that I can copy code from. If you're looking to use my actual homelab setup, checkout simple-talos-cluster. It uses a terraform modules instead of a simple main.tf file as used in this repo to create VMs in proxmox.