Proxmox cloud-init VM

Description

This module creates a Proxmox VE virtual machine, that can be configured on boot with cloud-init. To configure the VM on boot via cloud-init, you have to pass a user-data and network-data file.
Both files can be terraform template files.

Setup

What the module affects

  • Creates a virtual machine in your Proxmox VE cluster

  • Creates a snippet in your Proxmox VE cluster

  • Creates a MAC address as terraform resource

Setup Requirements

Install and configured these providers as documented at their corresponding terraform registry entries.

Beginning with this module

This module uses two providers for Proxmox VE and both providers relate to the name proxmox, therefore they have to be named explicitly. This example demonstrates how to set this up. Moreover you have to pass the explicit provider name to each module with the providers attribute.
A basic example to use this module can be found in the example/main. This example requires static userdata and netdata templates.

Usage

Following code is an example of how to use the module with only required variables. !It does not work when copy pasting, cause template values must be paths to a valid file!

link:example/main.tf[role=include]

The module is designed for cloud-init support. Therefore it can only be used with a user_data and net_data configuration.
It is possible to use string templates as user_data and net_data to configure cloud-init. To pass variables to the templates use the userdata_vars and netdata_vars attributes of this module:

userdata_vars = {
  key = "value"
}

netdata_vars  = {
  key = "value"
}

If the added network interfaces are supposed to have static IP addresses, add the address to the interfaces map:

interfaces = {
  eth0 = {
    net_bridge  = "vmbr0"
    net_vlan    = "0"
    ip4_address = "192.168.0.10/24"
  }
}

To use the key in a cloud-init user_data or net_data terraform template you can refer to interfaces.eth0.ip4_address in the template to use the IP set for the interfaces.

Variables

Following table contains all variables supported by this module. Using these variables it is possible to configure and customize the vm. If the default is empty (-), then the variable is required.

Variable Defaults Description

name

-

Name of the vm displayed in proxmox.

id

null

VM id, if null will use next available.

node_name

-

Name of the node where the vm should be deployed.

template

-

Name of a vm template that should be copied.

onboot

false

Whether or not the vm should be started on boot.

startup

null

Configures startup and shutdown behaviour.

cpu_cores

4

Maximum number of usable cpus for this vm.

cpu_vcpu

2

Number of vms available to the vm.

mem_size

1024

Memory size.

disk

[{disk_datastore = "local-lvm", disk_size = "10G"}]

Configure virtual disks for the vm.

interfaces

-

Configure interfaces for the vm. Typ is map(map(string)). Required keys are net_bridge and net_vlan.

description

clout-init vm

Description for the vm displayed in the description section in proxmox.

userdata_template

-

Path to cloud init user-data template.

netdata_template

-

Path to cloud init network-data template.

userdata_vars

null

Host specific user data values. Can be used if the template contains variables.

netdata_vars

null

Host specific net data values. Can be used if the template contains variables.

mac_prefx

[100, 179, 121]

MAC address prefix for interfaces. Can also be a full MAC address.

Limitations

  • This module is totally based around cloud-init so you have to provide user-data and net-data files

  • Without a cloud-init image it is not possible to configure the operating system of the VMs