Skip to content

Latest commit

 

History

History

terraform

Terraform + Proxmox + cloud-init = 🤌

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.

Usage

Prerequisites

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.

Run It

  1. 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
  2. Modify main.tf to suit your needs. You may also need to pass in users to the module since I've defaulted it to my needs in modules/cloud_init/vars.tf. You may also want to modify modules/cloud_init/cloud-init.tfpl if you want to customize your cloud-init configuration.
  3. Initialize Terraform
    $ tf init
  4. Apply Terraform
    $ tf apply
    You should see Terraform at work and eventually a prompt asking "Do you want to perform these actions?". Enter yes if you want to do so, and watch Terraform create virtual machines that use cloud-init!

Resources