From b9d8cd04d43c4cdf76fdbc1405ccaa0712a8e1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C4=83t=C4=83lin?= Date: Mon, 12 Feb 2024 17:24:17 +0100 Subject: [PATCH] feat: migrate terraform from https://gitlab.com/fukurokuju/vm-foundation --- .gitignore | 13 ++++++ tofu/modules/proxmox-vm/main.tf | 45 +++++++++++++++++++ tofu/modules/proxmox-vm/variables.tf | 66 ++++++++++++++++++++++++++++ tofu/modules/truenas-vm/main.tf | 8 ++++ tofu/modules/truenas-vm/variables.tf | 0 tofu/proxmox/.terraform.lock.hcl | 46 +++++++++++++++++++ tofu/proxmox/main.tf | 48 ++++++++++++++++++++ tofu/proxmox/sample.env | 4 ++ tofu/proxmox/vars.tf | 0 tofu/truenas/main.tf | 0 tofu/truenas/vars.tf | 0 11 files changed, 230 insertions(+) create mode 100644 tofu/modules/proxmox-vm/main.tf create mode 100644 tofu/modules/proxmox-vm/variables.tf create mode 100644 tofu/modules/truenas-vm/main.tf create mode 100644 tofu/modules/truenas-vm/variables.tf create mode 100644 tofu/proxmox/.terraform.lock.hcl create mode 100644 tofu/proxmox/main.tf create mode 100644 tofu/proxmox/sample.env create mode 100644 tofu/proxmox/vars.tf create mode 100644 tofu/truenas/main.tf create mode 100644 tofu/truenas/vars.tf diff --git a/.gitignore b/.gitignore index a5bd9d8..36032ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,16 @@ +**/.terraform/* +*.tfstate +*.tfstate.* +crash.*.log +*.tfvars +*.tfvars.json +override.tf +override.tf.json +*_override.tf +*_override.tf.json +.terraformrc +terraform.rc +*.retry .idea/ secrets.yaml .env \ No newline at end of file diff --git a/tofu/modules/proxmox-vm/main.tf b/tofu/modules/proxmox-vm/main.tf new file mode 100644 index 0000000..c46c905 --- /dev/null +++ b/tofu/modules/proxmox-vm/main.tf @@ -0,0 +1,45 @@ +terraform { + required_providers { + proxmox = { + source = "thegameprofi/proxmox" + version = "2.9.15" + } + } +} + +resource "proxmox_vm_qemu" "vm" { + name = var.vm_name + target_node = var.node_name + vmid = var.vm_id + clone = var.cloud_init_template + os_type = "cloudinit" + qemu_os = "other" + ipconfig0 = var.ipconfig0 + cores = var.core_count + sockets = 1 + pool = "k3s" + memory = var.memory + ciuser = var.ci_username + agent = 0 + serial { + id = 0 + type = "socket" + } + disk { + size = "50G" + storage = var.disk_storage_name + type = "scsi" + } + network { + bridge = var.network_bridge_name + firewall = false + link_down = false + model = "virtio" + mtu = 0 + queues = 0 + rate = 0 + tag = -1 + } + sshkeys = var.ssh_keys + nameserver = "192.168.1.7 192.168.1.3" +} diff --git a/tofu/modules/proxmox-vm/variables.tf b/tofu/modules/proxmox-vm/variables.tf new file mode 100644 index 0000000..313b7fa --- /dev/null +++ b/tofu/modules/proxmox-vm/variables.tf @@ -0,0 +1,66 @@ +variable "vm_name" { + description = "Name of the VM" + type = string +} + +variable "node_name" { + description = "Name of the Proxmox node" + type = string +} + +variable "vm_id" { + description = "ID of the new VM" + type = number +} + +variable "cloud_init_template" { + description = "Cloud-init enabled template to be cloned" + type = string + default = "ci-debian12" +} + +variable "ipconfig0" { + description = "Default inet configuration" + type = string +} + +variable "ci_username" { + description = "Cloud-init username" + type = string + default = "ci" +} + + +variable "memory" { + description = "Available RAM, in MB" + type = number + default = 512 +} + +variable "core_count" { + description = "Available cores per socket" + type = number + default = 2 + +} + +variable "network_bridge_name" { + description = "Network bridge name" + type = string + default = "vmbr0" +} + +variable "ssh_keys" { + description = "SSH public keys to be provisioned" + type = string + default = <