From 9286c98073ece3576bc01faaf28712b23d57cef7 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 2 Sep 2025 07:25:44 +0200 Subject: [PATCH] some new setup --- create-ubuntu-cloudinit-template.sh | 43 +++ flake.lock | 26 ++ flake.nix | 2 +- infrastructure-admin/main.tf | 263 ++++++++++++++++++ infrastructure-admin/outputs.tf | 0 infrastructure-admin/terraform.tfvars | 34 +++ .../values/coredns-values.yaml | 13 + .../values/gitlab-values.yaml | 19 ++ .../values/grafana-values.yaml | 12 + infrastructure-admin/values/loki-values.yaml | 2 + .../values/promtail-values.yaml | 0 infrastructure-admin/variables.tf | 25 ++ .../main.tf | 0 .../modules/syslog/main.tf | 0 14 files changed, 438 insertions(+), 1 deletion(-) create mode 100644 create-ubuntu-cloudinit-template.sh create mode 100644 flake.lock create mode 100644 infrastructure-admin/main.tf create mode 100644 infrastructure-admin/outputs.tf create mode 100644 infrastructure-admin/terraform.tfvars create mode 100644 infrastructure-admin/values/coredns-values.yaml create mode 100644 infrastructure-admin/values/gitlab-values.yaml create mode 100644 infrastructure-admin/values/grafana-values.yaml create mode 100644 infrastructure-admin/values/loki-values.yaml create mode 100644 infrastructure-admin/values/promtail-values.yaml create mode 100644 infrastructure-admin/variables.tf rename {terraform => infrastructure-softwarefactory}/main.tf (100%) rename {terraform => infrastructure-softwarefactory}/modules/syslog/main.tf (100%) diff --git a/create-ubuntu-cloudinit-template.sh b/create-ubuntu-cloudinit-template.sh new file mode 100644 index 0000000..5908111 --- /dev/null +++ b/create-ubuntu-cloudinit-template.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Script to create an Ubuntu 22.04 cloud-init template in Proxmox + +set -e + +# --- CONFIG --- +VMID=9000 +VM_NAME="ubuntu-22.04-cloudinit" +MEMORY=2048 +CORES=2 +STORAGE="local-lvm" # Change if using different storage +BRIDGE="vmbr0" +IMG_URL="https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" +IMG_FILE="/tmp/jammy-server-cloudimg-amd64.img" + +echo "==> Downloading Ubuntu 22.04 cloud image..." +wget -O "$IMG_FILE" "$IMG_URL" + +echo "==> Creating VM $VMID ($VM_NAME)..." +qm create $VMID --name $VM_NAME --memory $MEMORY --cores $CORES --net0 virtio,bridge=$BRIDGE + +echo "==> Importing disk to $STORAGE..." +qm importdisk $VMID "$IMG_FILE" $STORAGE + +echo "==> Attaching disk..." +qm set $VMID --scsihw virtio-scsi-pci --scsi0 ${STORAGE}:vm-${VMID}-disk-0 + +echo "==> Adding cloud-init drive..." +qm set $VMID --ide2 ${STORAGE}:cloudinit + +echo "==> Setting boot options..." +qm set $VMID --boot c --bootdisk scsi0 + +echo "==> Enabling serial console..." +qm set $VMID --serial0 socket --vga serial0 + +echo "==> Converting VM $VMID to template..." +qm template $VMID + +echo "==> Cleaning up..." +rm -f "$IMG_FILE" + +echo "✅ Template $VM_NAME (VMID $VMID) created successfully!" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d425057 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1756125398, + "narHash": "sha256-XexyKZpf46cMiO5Vbj+dWSAXOnr285GHsMch8FBoHbc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3b9f00d7a7bf68acd4c4abb9d43695afb04e03a5", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index fa11928..59a8085 100644 --- a/flake.nix +++ b/flake.nix @@ -14,7 +14,7 @@ in pkgs.mkShell { buildInputs = with pkgs; [ - vscode-extensions.hashicorp.terraform + terraform ]; }; }; diff --git a/infrastructure-admin/main.tf b/infrastructure-admin/main.tf new file mode 100644 index 0000000..0224066 --- /dev/null +++ b/infrastructure-admin/main.tf @@ -0,0 +1,263 @@ +terraform { + required_providers { + proxmox = { + source = "Telmate/proxmox" + version = "3.0.2-rc04" + } + random = { + source = "hashicorp/random" + version = "3.7.2" + } + kubernetes = { + source = "hashicorp/kubernetes" + version = "2.38.0" + } + helm = { + source = "hashicorp/helm" + version = "3.0.2" + } + } +} + +provider "proxmox" { + pm_api_url = var.proxmox_url + pm_user = var.proxmox_user + pm_password = var.proxmox_password + pm_tls_insecure = var.proxmox_tls_insecure +} + +# ---------------------- +# Generate k3s token +# ---------------------- +resource "random_password" "k3s_token" { + length = 32 + special = false +} + +# ---------------------- +# Controller VM +# ---------------------- +resource "proxmox_vm_qemu" "controller" { + name = "k3s-controller" + target_node = var.target_nodes["controller"] + clone = var.template_id + full_clone = true + cores = 2 + sockets = 1 + memory = 4096 + scsihw = "virtio-scsi-pci" + disk { + size = "20G" + storage = var.storage + type = "scsi" + } + network { bridge = var.bridge } + ipconfig0 = "ip=${var.controller_ip}/${var.netmask},gw=${var.gateway}" + ciuser = "ubuntu" + citype = "cloud-init" + sshkeys = var.ssh_public_key + + cicustom = <