Initial Commit

This commit is contained in:
Matthew McKinnon 2024-10-26 22:29:05 +10:00
commit 0518ee5343
7 changed files with 505 additions and 0 deletions

5
.gitignore vendored Executable file
View File

@ -0,0 +1,5 @@
terraform.auto.tfvars
.terraform
tokens.txt
terraform.tfstate*

70
.terraform.lock.hcl generated Normal file
View File

@ -0,0 +1,70 @@
# This file is maintained automatically by "tofu init".
# Manual edits may be lost in future updates.
provider "registry.opentofu.org/hashicorp/local" {
version = "2.5.2"
hashes = [
"h1:6lS+5A/4WFAqY3/RHWFRBSiFVLPRjvLaUgxPQvjXLHU=",
"zh:25b95b76ceaa62b5c95f6de2fa6e6242edbf51e7fc6c057b7f7101aa4081f64f",
"zh:3c974fdf6b42ca6f93309cf50951f345bfc5726ec6013b8832bcd3be0eb3429e",
"zh:5de843bf6d903f5cca97ce1061e2e06b6441985c68d013eabd738a9e4b828278",
"zh:86beead37c7b4f149a54d2ae633c99ff92159c748acea93ff0f3603d6b4c9f4f",
"zh:8e52e81d3dc50c3f79305d257da7fde7af634fed65e6ab5b8e214166784a720e",
"zh:9882f444c087c69559873b2d72eec406a40ede21acb5ac334d6563bf3a2387df",
"zh:a4484193d110da4a06c7bffc44cc6b61d3b5e881cd51df2a83fdda1a36ea25d2",
"zh:a53342426d173e29d8ee3106cb68abecdf4be301a3f6589e4e8d42015befa7da",
"zh:d25ef2aef6a9004363fc6db80305d30673fc1f7dd0b980d41d863b12dacd382a",
"zh:fa2d522fb323e2121f65b79709fd596514b293d816a1d969af8f72d108888e4c",
]
}
provider "registry.opentofu.org/hashicorp/null" {
version = "3.2.3"
hashes = [
"h1:LF8arSzHfhbyQSFtTMTYEqCM34klzrbAQBJMHYCs9d8=",
"zh:1d57d25084effd3fdfd902eca00020b34b1fb020253b84d7dd471301606015ac",
"zh:65b7f9799b88464d9c2ec529713b7f52ea744275b61a8dc86cdedab1b2dcb933",
"zh:80d3e9c95b7b4ae7c54005cd127cae82e5c53d2b7023ef24c147337bac9dadd9",
"zh:841b60c07683e4bf456799ccd718896fdafdcc2c49252ae09967f2e74d8c8a03",
"zh:8fa1c592a9c78222e35713c6edb3f1f818a4c6f3524a30a209f0a7e919827b68",
"zh:bb795cc1429e09466840c09d39a28edf1db5070b1ec76822fc1173906a264572",
"zh:da1784818a89bea29dfe660632f0060a7a843e4e564d74435fbeca002b0f7d2a",
"zh:f409bf21b1cdaa6dac47cd79806f3d93f67e9507fe4dbf33b0165335f53bc2e1",
"zh:fbea7a1ff84b430ba9594698e93196d81d03e4036de3d1cafccb2a96d5b38581",
"zh:fbf0c84663a7e85881388d7d71ac862184f05fbf2d17ecf76bc5d3d7503ea260",
]
}
provider "registry.opentofu.org/hashicorp/template" {
version = "2.2.0"
hashes = [
"h1:tdS0otiAtvUV8uLJWJNfcqOPo3llj7FyRzExw6X1srY=",
"zh:374c28bafc43cd65e578cb209efc9eee4c1cec7618f451528e928db98059e8c8",
"zh:6a2982e70fbc2ab2668d624c648ef2eb32243c1a1185246b03991a7a21326db9",
"zh:af83169c21bb13f141510a349e1f70cf7d893247a269bd71cad74dd22f1df0f5",
"zh:b81a5bedc91a1a81b938c393247248d6c3d1bd8ea685541f9c858908c0afb6b3",
"zh:de15486244af2d29d44d510d647cd6e0b1408e89952261013c572b7c9bfd744b",
]
}
provider "registry.opentofu.org/telmate/proxmox" {
version = "3.0.1-rc4"
constraints = "3.0.1-rc4"
hashes = [
"h1:wTzPTXWFxydIF6yUIkBnGQRQs0A1eWJadqyQ7EJHeAU=",
"zh:1070aff02aebeadf130368b0082e76d976f61464b3bb29c1c5a7866bb14c7380",
"zh:3cd96c232a12cf3bbb0e874508e5ff14116ef347d60db20db17ad87bb161ee22",
"zh:4f75954f3e68159ed969e3eac27485166103058eff3f99186d805816c6f8eb66",
"zh:55572fd22f7c62813a691fe0d017b2a57a34f3b4e1c40af6c2197731878ebf84",
"zh:6536402b2eff0a754ff975c39318c3c0b47dfa2dc4461d34a8c55ba493288d9f",
"zh:735f4283286cb78fe28b4ad001771c460f1963ee640e027467eb199d80a6c257",
"zh:90a675455c5812d90acbf44bfee347c2318b13565c68bcf64b452dbe6c2a629a",
"zh:9bbfe89d3f0997a26d7636d5c2d7244beccf92371d17073583299b1b74e1ab9c",
"zh:9ed8ecb50c4ed8555ffe1544325de07db678e2877f7c4637fbfaf02d5f004100",
"zh:b1e362ebd234aa82a38ffcfa4e74295e8a23811edff8af88f79372ba18ef0918",
"zh:c652faede363a91ad3a148cdd1b3d9c3ab8bac1b94d92ce89eb6e1ddadc99cc1",
"zh:d803958e5e465095cc0d5741abf0abd80b5fd3d1c076b40880a136e737bb06d0",
"zh:fa12bd372e39c8ac6295503f88884f328971834e109fcc015322fc9ab5fe858f",
"zh:fb7abe461d36f9868a0a6728320e482ecd54e047c2876dce85d5c2143eba3b8f",
]
}

109
cloudinit.tf Normal file
View File

@ -0,0 +1,109 @@
resource "null_resource" "cloud_init_deb" {
connection {
type = "ssh"
user = "root"
private_key = file("~/.ssh/pve2.comprofix.xyz")
host = "pve2.comprofix.xyz"
agent = true
}
provisioner "file" {
source = "files/cloud_init.cloud_config"
destination = "/var/lib/vz/snippets/cloud_init_deb.yml"
}
}
resource "proxmox_vm_qemu" "dev" {
# VM General Settings
target_node = "pve"
vmid = "500"
name = "dev"
desc = "Dev Server"
# VM Advanced General Settings
onboot = true
scsihw = "virtio-scsi-single"
# VM OS Settings
clone = "debian-12-generic-amd64"
clone_wait = 120
timeouts {
create = "1h"
delete = "1h"
}
# VM System Settings
agent = 1
machine = "q35"
qemu_os = "l26"
# VM CPU Settings
cores = 4
sockets = 1
cpu = "kvm64"
bios = "ovmf"
startup = ""
# VM Memory Settings
memory = 16384
# VM Network Settings
network {
bridge = "vmbr0"
model = "virtio"
tag = "10"
}
efidisk {
efitype = "4m"
storage = "local-zfs"
}
disks {
ide {
ide2 {
cdrom {
passthrough = false
}
}
ide3 {
cloudinit {
storage = "local-zfs"
}
}
}
scsi {
scsi0 {
disk {
size = 20
storage = "local-zfs"
}
}
}
}
# VM Cloud-Init Settings
os_type = "cloud-init"
cicustom = "vendor=local:snippets/cloud_init_deb.yml"
#cloudinit_cdrom_storage = "local-zfs"
# (Optional) IP Address and Gateway
ipconfig0 = "ip=10.10.10.22/24,gw=10.10.10.1"
nameserver = "10.10.10.1"
# (Optional) Default User
ciuser = "${var.ci_user}"
cipassword = "${var.ci_password}"
# (Optional) Add your SSH Public KEY
sshkeys = <<EOF
${ var.ssh_key }
EOF
}

View File

@ -0,0 +1,19 @@
#cloud-config
packages:
- htop
- vim-nox
- git
- zsh
- curl
- wget
- python3
- python3-pip
- nfs-common
- cron
- jq
- sudo
- logwatch
- sendemail
runcmd:
- "bash /usr/local/bin/notify.sh"

240
main.backup Executable file
View File

@ -0,0 +1,240 @@
# Proxmox Full-Clone
# ---
# Create a new VM from a clone
resource "proxmox_vm_qemu" "docker" {
# VM General Settings
target_node = "pve"
vmid = "101"
name = "docker"
desc = "Docker Server"
# VM Advanced General Settings
onboot = true
scsihw = "virtio-scsi-single"
# VM OS Settings
clone = "debian-12-generic-amd64"
clone_wait = 45
timeouts {
create = "20m"
delete = "10m"
}
# VM System Settings
agent = 1
machine = "q35"
qemu_os = "l26"
# VM CPU Settings
cores = 1
sockets = 4
cpu = "kvm64"
bios = "ovmf"
startup = "order=2,up=600"
# VM Memory Settings
memory = 16384
# VM Network Settings
network {
bridge = "vmbr0"
model = "virtio"
tag = "10"
}
efidisk {
efitype = "4m"
storage = "local-zfs"
}
disks {
ide {
ide2 {
cdrom {
passthrough = false
}
}
ide3 {
cloudinit {
storage = "local-zfs"
}
}
}
scsi {
scsi0 {
disk {
size = 80
storage = "local-zfs"
}
}
}
}
# VM Cloud-Init Settings
os_type = "cloud-init"
#cloudinit_cdrom_storage = "local-zfs"
# (Optional) IP Address and Gateway
ipconfig0 = "ip=10.10.10.5/24,gw=10.10.10.1"
nameserver = "10.10.10.1"
# (Optional) Default User
ciuser = "${var.ci_user}"
cipassword = "${var.ci_password}"
# # (Optional) Add your SSH Public KEY
# sshkeys = <<EOF
# ${ var.ssh_key }
# EOF
}
resource "proxmox_vm_qemu" "jellyfin" {
# VM General Settings
target_node = "pve"
vmid = "102"
name = "jellyfin"
# VM Advanced General Settings
onboot = true
startup = "order=3,up=300"
scsihw = "virtio-scsi-single"
# VM OS Settings
clone = "debian-12-generic-amd64"
clone_wait = 45
timeouts {
create = "20m"
delete = "10m"
}
# VM System Settings
agent = 1
machine = "q35"
qemu_os = "l26"
# VM CPU Settings
cores = 6
sockets = 1
cpu = "host"
bios = "ovmf"
# VM Memory Settings
memory = 16384
# VM Network Settings
network {
bridge = "vmbr0"
model = "virtio"
tag = "10"
}
efidisk {
efitype = "4m"
storage = "local-zfs"
}
disks {
ide {
ide2 {
cdrom {
passthrough = false
}
}
ide3 {
cloudinit {
storage = "local-zfs"
}
}
}
scsi {
scsi0 {
disk {
size = 40
storage = "local-zfs"
}
}
}
}
# VM Cloud-Init Settings
os_type = "cloud-init"
#cloudinit_cdrom_storage = "local-zfs"
# (Optional) IP Address and Gateway
ipconfig0 = "ip=10.10.10.7/24,gw=10.10.10.1"
nameserver = "10.10.10.1"
# (Optional) Default User
ciuser = "${var.ci_user}"
cipassword = "${var.ci_password}"
# # # (Optional) Add your SSH Public KEY
# sshkeys = <<EOF
# ${ var.ssh_key }
# EOF
}
resource "proxmox_lxc" "omada" {
# VM General Settings
target_node = "pve"
vmid = "200"
hostname = "omada"
ostemplate = "local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst"
password = "${var.ci_password}"
memory = 4096
swap = 512
cores = 2
# VM Advanced General Settings
onboot = true
start = true
startup = "order=1000"
timeouts {
create = "20m"
delete = "10m"
}
# VM Memory Settingsport 2019
unprivileged = true
features {
nesting = true
}
// Terraform will crash without rootfs defined
rootfs {
storage = "local-zfs"
size = "8G"
}
network {
name = "eth0"
bridge = "vmbr0"
ip = "10.10.40.2/24"
gw = "10.10.40.1"
tag = "40"
}
# # (Optional) Add your SSH Public KEY
ssh_public_keys = <<EOF
${ var.ssh_key }
EOF
}

56
provider.tf Executable file
View File

@ -0,0 +1,56 @@
# Proxmox Provider
# ---
# Initial Provider Configuration for Proxmox
terraform {
required_version = ">= 0.13.0"
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = "3.0.1-rc4"
}
}
}
variable "proxmox_api_url" {
type = string
}
variable "proxmox_api_token_id" {
type = string
}
variable "proxmox_api_token_secret" {
type = string
}
variable "ci_user" {
type = string
}
variable "ci_password" {
type = string
}
variable "ssh_key" {
type = string
}
variable "teams" {
type = string
}
provider "proxmox" {
pm_api_url = var.proxmox_api_url
pm_api_token_id = var.proxmox_api_token_id
pm_api_token_secret = var.proxmox_api_token_secret
pm_timeout = 3600
pm_parallel = 2 # Fix vm hdd lock timeout
# (Optional) Skip TLS Verification
# pm_tls_insecure = true
}

6
terraform.auto.tfvars.example Executable file
View File

@ -0,0 +1,6 @@
proxmox_api_url = "https://0.0.0.0:8006/api2/json" # Your Proxmox IP Address
proxmox_api_token_id = "terraform@pam!terraform" # API Token ID
proxmox_api_token_secret = "your-api-token-secret"
ci_user = "administrator"
ci_password = "your-ci-password"
ssh_key = "your-ssh-key"