Skip to main content
Infrastructure Setup: Packer and Terraform
Overview

Infrastructure Setup: Packer and Terraform

Merox
Merox HPC Sysadmin
1 min read

This covers Packer and Terraform configuration for building the VM template and provisioning infrastructure on Proxmox.

Packer

API Credentials

Holds your Proxmox API credentials. Do not commit this to a public repository.

proxmox_api_url = "https://your-proxmox-ip-or-fqdn/api2/json"
proxmox_api_token_id = "terraform_user@pam!homelab"
proxmox_api_token_secret = "your-proxmox-api-token-secret"

To generate a Proxmox API token: tutorial. More Packer examples: here.

Plugin Configuration

Plugin configuration for the Proxmox provider:

packer {
required_plugins {
proxmox-iso = {
version = ">= 1.0.0"
source = "github.com/hashicorp/proxmox"
}
}
}

VM Template Definition

Replace YOUR_PROXMOX_NODE_NAME with your Proxmox node name and YOUR_IP_DEPLOYMENT_MACHINE with the IP of the machine running the deploy script.

Cloud-Init User Data

Replace YOUR_SSH_KEY with the SSH key generated by homelab_deploy.sh.

Terraform

Credentials and Variables

Holds credentials for Proxmox. Do not commit this to a public repository.

proxmox_api_url = "https://your-proxmox-ip-or-fqdn/api2/json"
proxmox_api_token_id = "terraform_user@pam!homelab"
proxmox_api_token_secret = "your-proxmox-api-token-secret"
proxmox_host = "proxmox-host-ip"
proxmox_user = "proxmox-user"
proxmox_password = "proxmox-password"

VM Module Configuration

Replace all placeholders with your values:

  • YOUR_PROXMOX_NODE_NAME
  • IP_MACHINE — VM deployment IP
  • GateWay_IP
  • IP_DEPLOYMENT — same as IP_MACHINE
  • YOUR_SSH_KEY — generated by homelab_deploy.sh

If you’re not using NFS, comment out this block:

Warning
resource "null_resource" "run_ansible_docker" {
depends_on = [local_file.ansible_inventory]
provisioner "local-exec" {
command = "LC_ALL=C.UTF-8 LANG=C.UTF-8 ansible-playbook -i ../ansible/inventory/inventory.ini ../ansible/roles/nfs_mount/main.yml"
}
}

Other things configured in this file: locales, root SSH login, SSH key auth, and the Ansible integration trigger.

Next Steps

Proceed to the Deployment guide.

Share this post