diff --git a/terraform/.envrc b/terraform/.envrc new file mode 100644 index 0000000..2c8269e --- /dev/null +++ b/terraform/.envrc @@ -0,0 +1 @@ +use flake ../#opentofu diff --git a/terraform/.gitignore b/terraform/.gitignore new file mode 100644 index 0000000..8a7f7b7 --- /dev/null +++ b/terraform/.gitignore @@ -0,0 +1,42 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tofu +override.tf.json +override.tofu.json +*_override.tf +*_override.tofu +*_override.tf.json +*_override.tofu.json + +# Ignore transient lock info files created by tofu apply +.terraform.tfstate.lock.info + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf +# !example_override.tofu + +# Include tfplan files to ignore the plan output of command: tofu plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc diff --git a/terraform/busch/.terraform.lock.hcl b/terraform/busch/.terraform.lock.hcl new file mode 100644 index 0000000..6ce99f5 --- /dev/null +++ b/terraform/busch/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "tofu init". +# Manual edits may be lost in future updates. + +provider "registry.opentofu.org/telmate/proxmox" { + version = "3.0.2-rc07" + constraints = "3.0.2-rc07" + hashes = [ + "h1:zp5hpQJQ4t4zROSLqdltVpBO+Riy9VugtfFbpyTw1aM=", + "zh:2ee860cd0a368b3eaa53f4a9ea46f16dab8a97929e813ea6ef55183f8112c2ca", + "zh:415965fd915bae2040d7f79e45f64d6e3ae61149c10114efeac1b34687d7296c", + "zh:6584b2055df0e32062561c615e3b6b2c291ca8c959440adda09ef3ec1e1436bd", + "zh:65dcfad71928e0a8dd9befc22524ed686be5020b0024dc5cca5184c7420eeb6b", + "zh:7253dc29bd265d33f2791ac4f779c5413f16720bb717de8e6c5fcb2c858648ea", + "zh:7ec8993da10a47606670f9f67cfd10719a7580641d11c7aa761121c4a2bd66fb", + "zh:999a3f7a9dcf517967fc537e6ec930a8172203642fb01b8e1f78f908373db210", + "zh:a50e6df7280eb6584a5fd2456e3f5b6df13b2ec8a7fa4605511e438e1863be42", + "zh:b25b329a1e42681c509d027fee0365414f0cc5062b65690cfc3386aab16132ae", + "zh:c028877fdb438ece48f7bc02b65bbae9ca7b7befbd260e519ccab6c0cbb39f26", + "zh:cf0eaa3ea9fcc6d62793637947f1b8d7c885b6ad74695ab47e134e4ff132190f", + "zh:d5ade3fae031cc629b7c512a7b60e46570f4c41665e88a595d7efd943dde5ab2", + "zh:f388c15ad1ecfc09e7361e3b98bae9b627a3a85f7b908c9f40650969c949901c", + "zh:f415cc6f735a3971faae6ac24034afdb9ee83373ef8de19a9631c187d5adc7db", + ] +} diff --git a/terraform/busch/main.tf b/terraform/busch/main.tf new file mode 100644 index 0000000..966ec14 --- /dev/null +++ b/terraform/busch/main.tf @@ -0,0 +1,46 @@ +terraform { + required_providers { + proxmox = { + source = "telmate/proxmox" + version = "3.0.2-rc07" + } + } +} + +provider "proxmox" { + pm_api_url = var.proxmox_api_url + pm_api_token_id = var.proxmox_token_id + pm_api_token_secret = var.proxmox_token_secret + pm_tls_insecure = true +} + +module "truenas" { + source = "./modules/proxmox-vm" + + name = "truenas" + target_node = "busch" + vmid = 100 + memory = 8192 + cpu_cores = 2 + disk_storage = "local" + disk_size = "32G" + iso_path = "local:iso/TrueNAS-SCALE-25.10.2.1.iso" + startup_order = 1 + + mapped_pcie_devices = ["HBA"] +} + +module "nixos-docker" { + source = "./modules/proxmox-vm" + + name = "nixos-docker" + target_node = "busch" + vmid = 101 + memory = 4096 + cpu_cores = 2 + disk_storage = "truenas-lvm" + disk_size = "64G" + iso_path = "local:iso/latest-nixos-minimal-x86_64-linux.iso" + startup_order = 2 + startup_delay = 240 +} diff --git a/terraform/busch/modules/proxmox-vm/main.tf b/terraform/busch/modules/proxmox-vm/main.tf new file mode 100644 index 0000000..89ddcf3 --- /dev/null +++ b/terraform/busch/modules/proxmox-vm/main.tf @@ -0,0 +1,66 @@ +terraform { + required_providers { + proxmox = { + source = "telmate/proxmox" + version = "3.0.2-rc07" + } + } +} + +resource "proxmox_vm_qemu" "truenas" { + name = var.name + description = var.description + target_node = var.target_node + vmid = var.vmid + machine = length(var.mapped_pcie_devices) == 0 ? "pc" : "q35" + memory = var.memory + balloon = 1024 + scsihw = "virtio-scsi-pci" + boot = "order=scsi0;ide0" + start_at_node_boot = true + + cpu { + cores = var.cpu_cores + sockets = 1 + } + + disks { + scsi { + scsi0 { + disk { + storage = var.disk_storage + size = var.disk_size + } + } + } + ide { + ide0 { + cdrom { + iso = var.iso_path + } + } + } + } + + network { + id = 0 + bridge = "vmbr0" + model = "virtio" + } + + dynamic "pci" { + for_each = { for device in var.mapped_pcie_devices : index(var.mapped_pcie_devices, device) => device } + + content { + id = pci.key + mapping_id = pci.value + pcie = true + } + } + + startup_shutdown { + order = var.startup_order + startup_delay = var.startup_delay + } + +} diff --git a/terraform/busch/modules/proxmox-vm/variables.tf b/terraform/busch/modules/proxmox-vm/variables.tf new file mode 100644 index 0000000..fe75fcd --- /dev/null +++ b/terraform/busch/modules/proxmox-vm/variables.tf @@ -0,0 +1,64 @@ +variable "vmid" { + description = "ID of the VM to create" + type = string +} + +variable "name" { + description = "Name of the VM to create" + type = string +} + +variable "description" { + description = "Description of the VM to create" + type = string + default = null + nullable = true +} + +variable "target_node" { + description = "Name of the target node to create the VM on" + type = string +} + +variable "memory" { + description = "Memory to allocate for the VM" + type = string +} + +variable "cpu_cores" { + description = "Number of CPU cores to allocate for the VM" + type = number +} + +variable "disk_storage" { + description = "Name of the storage to store the disk on" + type = string + default = "local" +} + +variable "disk_size" { + description = "Size of the primary disk" + type = string +} + +variable "iso_path" { + description = "Path of the ISO to use to install an OS" + type = string +} + +variable "startup_order" { + description = "Order number of the VM in the startup chain" + type = number +} + +variable "startup_delay" { + description = "Startup delay in seconds" + type = number + default = -1 +} + +variable "mapped_pcie_devices" { + description = "PCI mappings" + type = list(string) + default = [] +} diff --git a/terraform/busch/plan b/terraform/busch/plan new file mode 100644 index 0000000..2532f9d Binary files /dev/null and b/terraform/busch/plan differ diff --git a/terraform/busch/variables.tf b/terraform/busch/variables.tf new file mode 100644 index 0000000..a352dd7 --- /dev/null +++ b/terraform/busch/variables.tf @@ -0,0 +1,10 @@ +variable "proxmox_api_url" { + description = "API URL, typically ends with `/api2/json`" +} + +variable "proxmox_token_id" { + description = "Token ID" +} +variable "proxmox_token_secret" { + description = "Token Secret" +}