Linux serverlinux web serverNETWORK ADMINISTRATIONS

Automate Homelab Deployment With Terraform & Proxmox

Terraform is a powerform ‘infrastructure as code’ tool to automate deployments. In this video I use it to create VMs in Proxmox ready for a Kubernetes or Docker Swarm cluster.

Examples Used:
https://github.com/JamesTurland/JimsGarage/tree/main/Terraform

Terraform:
https://developer.hashicorp.com/terraform?product_intent=terraform

Telmate/Proxmox:
https://github.com/Telmate/terraform-provider-proxmox
BPG/Proxmox:
https://github.com/bpg/terraform-provider-proxmox

Recommended Hardware: https://github.com/JamesTurland/JimsGarage/blob/main/Homelab-Buyer’s-Guide/Q3-2023.md

Discord: https://discord.gg/qW5vEBekz5
Twitter: https://twitter.com/jimsgarage_
Reddit: https://www.reddit.com/user/Jims-Garage
GitHub: https://github.com/JamesTurland/JimsGarage

00:00 – Overview of Terraform
05:39 – Code Overview
15:15 – Proxmox Configuration
16:32 – Starting Terraform
22:30 – Deploying with Terraform
25:06 – Outro

source

by Jim’s Garage

linux web server

29 thoughts on “Automate Homelab Deployment With Terraform & Proxmox

  • Thanks Jim, your clear and concise explanations of complex subject matter are some of the best – I’ve learnt so much from your videos !

  • I'm running the script exactly as you have shown in your video (with key variables changed of course) but some vms are not being created. For example, it will create master 1 and 3 but not 2. The Terraform process also never seems to finish even though the vms it has created are up. ??

  • I was thought this infrastructure as code could redeploy Proxmox OS With my configurations And vm's and containers

  • I look forward to the day you post a video on NixOS. NixOS is the future to linux computing. Hope you look into it and start making videos about it.

  • I don't know why my comments keep getting deleted, so I'll try once more.
    We also use terraform at work. Will you also make a video on Pulumi? It's open source and more flexible imho.

  • I looked at this provider a few months ago, and I couldn't get it to work. Really glad to see there is ongoing development for this proxmox provider. Not having a solid terraform provider is the only thing keeping me on VMware at the moment. It would be really nice if HashiCorp could work with the Proxmox devs to create a first party provider that stays up to date with the Proxmox API.

  • This is similar to something I've done – but I use proxmox containers nearly exclusively.

    I found the telmate provider and ran with it but later found bgp and realise now how better it is but switching seems like such a pain… I'll get around to it.

    Main comment refers back to containers and credentials. FYI connecting via API credentials has it's limitations as you can't created privileged containers (something I required to connect NFS shares from my storage device).

    With either of these modules you will need to switch to your root user credentials if you wanted to create privileged LXC containers.

    FYI I use terrafom for provisioning and ansible for config/ setup – keeping secrets in bitwarden and use the bitwarden ansible plugin to retrieve the secret

  • Great video! Next step to deploy from git+cd 😉

  • Great video! I'll have to revisit the Telmate plugin. I moved to the bpg plugin when Proxmox 8.1 broke Telmate and I saw development was stalled. Besides VMs and LXC containers, bpg can also manage other aspects of your Proxmox cluster like VLANS (nice for making sure all your Proxmox nodes have the same VLANs so migrating VMs will work). The official Ansible plugin for Terraform is also a mess. When you start going down that path, the provider GRPC error means the playbook run had an error which could have many causes. I've found setting TF_LOG=debug in the environment and capturing your playbook resource's .ansible_playbook_std{err,out} to a Terraform output variable to be most helpful with these.

  • Thanks for this video! I struggled a bit to see the link between the cloud-init tempate I created in proxmox and how to specify that parameters of it in terraform so that the vm is properly created (my vm would never boot because the hdd definitions were wrong or something). That link is now much more clear to me so thanks very much for that!
    One think I was wondering however, why does your use of the plugin seems so complicated, building it yourself and all? Am I missing something there, perhaps because you are using a liniux(/wsl2) prompt and I am simply using the windows binaries? Because in main.tf I simply have this

    terraform {

    required_version = ">=1.7.2"

    required_providers {

    proxmox = {

    source = "telmate/proxmox"

    version = "3.0.1-rc1"

    }

    }

    }

    And this works fine without having to compile any binaries or plugins myself 😊

  • Awesome video! I am actually working on the exact same project and I’m using your script as input to provision the cluster with a few tweaks

    The only thing I added into the process is packer. I preinstall packages for my K3s-ansible controller and I export the public SSH key onto a share during building the cloud init image. I also use the ansible server as my terraform and packer builder server. Just a bit of a chicken and egg problem.

    For my K3s nodes I inject this public ssh key and create the ansible user in the packer image.

    Once all done my ansible machine can immediately connect to all K3s nodes and start building the cluster.

    Still a work in progress but it’s super nice you are doing exactly what I’m working on and your videos are extremely useful

  • Speaking for terraformation, if you moved out of the garage to, say, a loft studio… would you then be known as Jim’s Loft?

  • Thanks Jim, I appreciate your videos a lot. btw it would be interesting to look into Ansible dynamic inventories for your next videos.

  • Can we talk about the elephant in the room here, that is Hashicorp and the new terraform licence? OpenTofu is definatrly the way forward in theory you should just be able to drop in OpenTofu and carry on the same with terraform.

  • The provider by bpg works like a charm as has been up-to-date ever since, compared to Telmate's. It also has resources & data sources for everything, starting from basic settings like the keyboard layout of Proxmox itself to firewall rules. Of course VMs & CTs are supported as well 😄 Telmate supports… 2.
    I can only recommend it, but sadly many users are being fouled by GitHub stars and other useless metrics.

  • You can Just as easy use ansible playbooks to spin up multiple vm's.

  • I hope that Talmate project gets legs under it and grows. It would be nice in a Proxmox cluster to be able to assign these VMs to various nodes in the deploy. eg three Proxmox nodes, this would then build a master and x workers per Proxmox node.

    I wonder if there is a provider for iDRAC7, could get real close to metal then. get three new dell servers, use Terraform to update them, provision disks, install Proxmox, setup the cluster, and CEPH; this run this to provision the VMs

  • to be fair, Terraform and Terrifying sound very similar.

  • You should try the bpg/proxmox provider instead of the telmate one, as it supports many more features. I also recently investigated Terraform on proxmox and I'm glad I found bpg's provider. It provides a wide range of resources and data sources for managing VMs, firewalls, files (VM images, snippets), etc., so you can configure your entire proxmox infrastructure in Terraform. One particularly useful feature is the ability to upload custom cloud-init snippets that I used to deploy scripts that set up my k3s cluster. Also, I found that bpg works more stable for me when I tried the telmate's provider I encountered a few times race conditions on the disk setup step that failed the terrafom apply command.

  • Great video! video suggestion- how to secure VMs/K8s clusters and use of tools like Wazuh etc…

  • my OCD would not handle the non-sequential VM IDs vs node names…great work as always

  • This is awesome! I'm looking forward to using it. Thanks Jim!

  • Thanks James. I tried telmate but it did not worked. I using now bpg provider and test the same. It will provision the required number of machines and create the host file for anisble then ansible will provision the k3s cluster with metallb. testing now longhorn and other apps provisioning. Thanks again for such informative videos

  • Didnt you leak your api tokens at 9:00 and a bit before when viewing providers config?

Comments are closed.