feature: Add Terraform BPG Proxmox provider related templates for automated FreeBSD VM creation

This commit is contained in:
Florian Paul Azim Hoberg 2024-08-30 17:57:28 +02:00
parent a04c089b38
commit f24faf9a18
4 changed files with 103 additions and 0 deletions

19
cloud-init/user-data.yml Normal file
View file

@ -0,0 +1,19 @@
package_upgrade: true
packages:
- qemu-guest-agent
timezone: Europe/Berlin
users:
- name: gyptazy
passwd: $6$F2NA9T240RZLC7cm$9JcyNJ6vHw0FidyCH7YlDGVE3.4y9K/KtWoCIcP1zb7Kdox/cPWwudNybjX.km11mmd2El5jDKTe0eLxI7s5l.
lock-passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
ssh_authorized_keys:
- AAAAC3NzaF1D4NTE5AAAAIJe45xj6fsadGHesfdadsJFGZxasdfads/gjVmr gyptazy
power_state:
delay: now
mode: reboot
message: Rebooting after cloud-init completion
condition: true

22
files.tf Normal file
View file

@ -0,0 +1,22 @@
resource "proxmox_virtual_environment_file" "freebsd14_cloud" {
content_type = "iso"
datastore_id = "local"
node_name = "virt01"
source_file {
path = "https://cdn.gyptazy.ch/files/amd64/freebsd/images/cloud/freebsd-14.0-ufs-2024-05-04.qcow2"
file_name = "freebsd-14.0-ufs-2024-05-04.img"
#checksum = "f472fa7af26aae23fdc92f4a729f083a6a10ce43b1f2049573382bc755c81750"
}
}
resource "proxmox_virtual_environment_file" "cloud_config" {
content_type = "snippets"
datastore_id = "local"
node_name = "virt01"
source_file {
path = "cloud-init/user-data.yml"
}
}

21
main.tf Normal file
View file

@ -0,0 +1,21 @@
terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.63.0"
}
}
}
provider "proxmox" {
endpoint = "https://cluster-vip02.gyptazy.ch:8006/"
username = "root@pam"
password = "p@ssw0rd!"
insecure = true
ssh {
agent = true
# TODO: uncomment and configure if using api_token instead of password
# username = "root"
}
}

41
virtual_machines.tf Normal file
View file

@ -0,0 +1,41 @@
resource "proxmox_virtual_environment_vm" "managed-vm33" {
name = "managed-vm33.boxybsd.com"
description = "Managed by Terraform"
tags = ["terraform"]
node_name = "virt01"
cpu {
cores = 1
}
memory {
dedicated = 2048
}
agent {
enabled = true
}
network_device {
bridge = "vmbr0"
}
disk {
datastore_id = "local-lvm"
file_id = proxmox_virtual_environment_file.freebsd14_cloud.id
interface = "scsi0"
size = 32
}
serial_device {}
initialization {
datastore_id = "local-lvm"
user_data_file_id = proxmox_virtual_environment_file.cloud_config.id
ip_config {
ipv4 {
address = "dhcp"
}
}
}
}