mirror of
https://github.com/vhaudiquet/homeprod.git
synced 2025-12-18 20:16:05 +00:00
infra: add r740 proxmox
This commit is contained in:
137
infra/r740/proxmox/ai.tf
Normal file
137
infra/r740/proxmox/ai.tf
Normal file
@@ -0,0 +1,137 @@
|
||||
resource "proxmox_virtual_environment_download_file" "ubuntu-latest-cloudimg" {
|
||||
content_type = "iso"
|
||||
datastore_id = "local"
|
||||
file_name = "noble-server-cloudimg-amd64.img"
|
||||
node_name = var.proxmox_node_name
|
||||
url = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "ai-cloud-config" {
|
||||
content_type = "snippets"
|
||||
datastore_id = "local"
|
||||
node_name = var.proxmox_node_name
|
||||
|
||||
source_raw {
|
||||
data = <<-EOF
|
||||
#cloud-config
|
||||
package_update: true
|
||||
packages:
|
||||
- git
|
||||
- ca-certificates
|
||||
- wget
|
||||
- curl
|
||||
- gnupg2
|
||||
- qemu-guest-agent
|
||||
runcmd:
|
||||
- systemctl enable --now qemu-guest-agent
|
||||
- install -m 0755 -d /etc/apt/keyrings
|
||||
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
||||
- chmod a+r /etc/apt/keyrings/docker.asc
|
||||
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
- apt-get update
|
||||
- apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
- apt install ubuntu-drivers-common
|
||||
- ubuntu-drivers install --gpgpu
|
||||
- curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
|
||||
- curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
|
||||
- apt-get update
|
||||
- export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.17.8-1
|
||||
- apt-get install -y nvidia-container-toolkit=$NVIDIA_CONTAINER_TOOLKIT_VERSION nvidia-container-toolkit-base=$NVIDIA_CONTAINER_TOOLKIT_VERSION libnvidia-container-tools=$NVIDIA_CONTAINER_TOOLKIT_VERSION libnvidia-container1=$NVIDIA_CONTAINER_TOOLKIT_VERSION
|
||||
- nvidia-ctk runtime configure --runtime=docker
|
||||
- systemctl restart docker
|
||||
EOF
|
||||
file_name = "ai-cloud-config.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "ai" {
|
||||
name = "ai-${var.proxmox_node_name}"
|
||||
node_name = var.proxmox_node_name
|
||||
on_boot = true
|
||||
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
tags = ["ubuntu", "ubuntu-latest", "docker", "terraform", "gpu", "ai"]
|
||||
|
||||
cpu {
|
||||
type = "host"
|
||||
cores = 20
|
||||
sockets = 2
|
||||
flags = []
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = 64536
|
||||
floating = 16192
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
model = "virtio"
|
||||
# mac_address = "BC:24:11:E2:F5:5B"
|
||||
vlan_id = 2
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
network_interface_names,
|
||||
mac_addresses,
|
||||
ipv4_addresses,
|
||||
ipv6_addresses,
|
||||
id,
|
||||
disk,
|
||||
initialization,
|
||||
vga,
|
||||
hostpci
|
||||
]
|
||||
}
|
||||
|
||||
boot_order = ["scsi0"]
|
||||
scsi_hardware = "virtio-scsi-single"
|
||||
|
||||
vga {
|
||||
type = "serial0"
|
||||
}
|
||||
|
||||
disk {
|
||||
interface = "scsi0"
|
||||
iothread = true
|
||||
datastore_id = "local-lvm"
|
||||
size = 330
|
||||
discard = "ignore"
|
||||
file_id = proxmox_virtual_environment_download_file.ubuntu-latest-cloudimg.id
|
||||
}
|
||||
|
||||
vm_id = 101
|
||||
|
||||
initialization {
|
||||
datastore_id = "local-lvm"
|
||||
interface = "ide2"
|
||||
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "dhcp"
|
||||
}
|
||||
}
|
||||
|
||||
user_account {
|
||||
keys = [trimspace(var.ssh_public_key)]
|
||||
password = var.machine_root_password
|
||||
username = "root"
|
||||
}
|
||||
|
||||
vendor_data_file_id = proxmox_virtual_environment_file.ai-cloud-config.id
|
||||
}
|
||||
|
||||
operating_system {
|
||||
type = "l26"
|
||||
}
|
||||
|
||||
tpm_state {
|
||||
version = "v2.0"
|
||||
}
|
||||
|
||||
serial_device {}
|
||||
}
|
||||
133
infra/r740/proxmox/build-latest.tf
Normal file
133
infra/r740/proxmox/build-latest.tf
Normal file
@@ -0,0 +1,133 @@
|
||||
resource "proxmox_virtual_environment_download_file" "ubuntu-questing-cloudimg" {
|
||||
content_type = "iso"
|
||||
datastore_id = "local"
|
||||
file_name = "questing-server-cloudimg-amd64.img"
|
||||
node_name = var.proxmox_node_name
|
||||
url = "https://cloud-images.ubuntu.com/questing/current/questing-server-cloudimg-amd64.img"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "build-latest-cloud-config" {
|
||||
content_type = "snippets"
|
||||
datastore_id = "local"
|
||||
node_name = var.proxmox_node_name
|
||||
|
||||
source_raw {
|
||||
data = <<-EOF
|
||||
#cloud-config
|
||||
package_update: true
|
||||
packages:
|
||||
- git
|
||||
- ca-certificates
|
||||
- wget
|
||||
- curl
|
||||
- gnupg2
|
||||
- qemu-guest-agent
|
||||
- build-essential
|
||||
- sbuild
|
||||
- mmdebstrap
|
||||
- qemu-user-binfmt
|
||||
- ubuntu-dev-tools
|
||||
- micro
|
||||
runcmd:
|
||||
- systemctl enable --now qemu-guest-agent
|
||||
- snap install lxd
|
||||
- lxd init --auto
|
||||
- snap install snapcraft --classic
|
||||
- usermod --add-subuids 100000-165535 --add-subgids 100000-165535 root
|
||||
- mkdir -p /root/.config/sbuild/
|
||||
- mkdir -p /root/.cache/sbuild/
|
||||
- echo -e "\$chroot_mode = 'unshare';\n\$unshare_mmdebstrap_keep_tarball = 1;\n1;\n" >/root/.config/sbuild/config.pl
|
||||
EOF
|
||||
file_name = "build-latest-cloud-config.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "build-latest" {
|
||||
name = "bw-${var.proxmox_node_name}"
|
||||
node_name = var.proxmox_node_name
|
||||
on_boot = true
|
||||
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
tags = ["ubuntu", "ubuntu-questing", "docker", "terraform", "build"]
|
||||
|
||||
cpu {
|
||||
type = "host"
|
||||
cores = 20
|
||||
sockets = 2
|
||||
flags = []
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = 64536
|
||||
floating = 16192
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
model = "virtio"
|
||||
vlan_id = 2
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
network_interface_names,
|
||||
mac_addresses,
|
||||
ipv4_addresses,
|
||||
ipv6_addresses,
|
||||
id,
|
||||
disk,
|
||||
initialization,
|
||||
vga
|
||||
]
|
||||
}
|
||||
|
||||
boot_order = ["scsi0"]
|
||||
scsi_hardware = "virtio-scsi-single"
|
||||
|
||||
vga {
|
||||
type = "serial0"
|
||||
}
|
||||
|
||||
disk {
|
||||
interface = "scsi0"
|
||||
iothread = true
|
||||
datastore_id = "local-lvm"
|
||||
size = 330
|
||||
discard = "ignore"
|
||||
file_id = proxmox_virtual_environment_download_file.ubuntu-questing-cloudimg.id
|
||||
}
|
||||
|
||||
vm_id = 201
|
||||
|
||||
initialization {
|
||||
datastore_id = "local-lvm"
|
||||
interface = "ide2"
|
||||
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "dhcp"
|
||||
}
|
||||
}
|
||||
|
||||
user_account {
|
||||
keys = [trimspace(var.ssh_public_key), trimspace(var.ssh_secondary_key)]
|
||||
password = var.machine_root_password
|
||||
username = "root"
|
||||
}
|
||||
|
||||
vendor_data_file_id = proxmox_virtual_environment_file.build-latest-cloud-config.id
|
||||
}
|
||||
|
||||
operating_system {
|
||||
type = "l26"
|
||||
}
|
||||
|
||||
tpm_state {
|
||||
version = "v2.0"
|
||||
}
|
||||
|
||||
serial_device {}
|
||||
}
|
||||
133
infra/r740/proxmox/docker.tf
Normal file
133
infra/r740/proxmox/docker.tf
Normal file
@@ -0,0 +1,133 @@
|
||||
resource "proxmox_virtual_environment_download_file" "debian-latest-cloudimg" {
|
||||
content_type = "iso"
|
||||
datastore_id = "local"
|
||||
file_name = "debian-13-generic-amd64.qcow2.img"
|
||||
node_name = var.proxmox_node_name
|
||||
url = "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-amd64.qcow2"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_file" "docker-machine-cloud-config" {
|
||||
content_type = "snippets"
|
||||
datastore_id = "local"
|
||||
node_name = var.proxmox_node_name
|
||||
|
||||
source_raw {
|
||||
data = <<-EOF
|
||||
#cloud-config
|
||||
package_update: true
|
||||
packages:
|
||||
- git
|
||||
- ca-certificates
|
||||
- wget
|
||||
- curl
|
||||
- gnupg2
|
||||
- qemu-guest-agent
|
||||
- nfs-common
|
||||
runcmd:
|
||||
- systemctl enable --now qemu-guest-agent
|
||||
- install -m 0755 -d /etc/apt/keyrings
|
||||
- curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
|
||||
- chmod a+r /etc/apt/keyrings/docker.asc
|
||||
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
- apt-get update
|
||||
- apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||
- docker swarm init
|
||||
- git clone https://github.com/vhaudiquet/homeprod /root/homeprod
|
||||
- mkdir /app
|
||||
- echo "truenas.lan:/mnt/fast_app_data/docker-homeprod /app nfs defaults,_netdev 0 0" >>/etc/fstab
|
||||
- mount -t nfs truenas.lan:/mnt/fast_app_data/docker-homeprod /app
|
||||
EOF
|
||||
file_name = "docker-machine-cloud-config.yaml"
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "docker-machine" {
|
||||
name = "docker-${var.proxmox_node_name}"
|
||||
node_name = var.proxmox_node_name
|
||||
on_boot = true
|
||||
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
tags = ["debian", "debian-latest", "docker", "terraform"]
|
||||
|
||||
cpu {
|
||||
type = "host"
|
||||
cores = 40
|
||||
sockets = 2
|
||||
flags = []
|
||||
}
|
||||
|
||||
memory {
|
||||
floating = 16192
|
||||
dedicated = 38768
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
model = "virtio"
|
||||
vlan_id = 2
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
network_interface_names,
|
||||
mac_addresses,
|
||||
ipv4_addresses,
|
||||
ipv6_addresses,
|
||||
id,
|
||||
disk,
|
||||
initialization,
|
||||
vga
|
||||
]
|
||||
}
|
||||
|
||||
boot_order = ["scsi0"]
|
||||
scsi_hardware = "virtio-scsi-single"
|
||||
|
||||
vga {
|
||||
type = "serial0"
|
||||
}
|
||||
|
||||
disk {
|
||||
interface = "scsi0"
|
||||
iothread = true
|
||||
datastore_id = "local-lvm"
|
||||
size = 128
|
||||
discard = "ignore"
|
||||
file_id = proxmox_virtual_environment_download_file.debian-latest-cloudimg.id
|
||||
}
|
||||
|
||||
vm_id = 701
|
||||
|
||||
initialization {
|
||||
datastore_id = "local-lvm"
|
||||
interface = "ide2"
|
||||
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "10.1.2.212/24"
|
||||
gateway = "10.1.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
user_account {
|
||||
keys = [trimspace(var.ssh_public_key)]
|
||||
password = var.machine_root_password
|
||||
username = "root"
|
||||
}
|
||||
|
||||
vendor_data_file_id = proxmox_virtual_environment_file.docker-machine-cloud-config.id
|
||||
}
|
||||
|
||||
operating_system {
|
||||
type = "l26"
|
||||
}
|
||||
|
||||
tpm_state {
|
||||
version = "v2.0"
|
||||
}
|
||||
|
||||
serial_device {}
|
||||
}
|
||||
95
infra/r740/proxmox/kube.tf
Normal file
95
infra/r740/proxmox/kube.tf
Normal file
@@ -0,0 +1,95 @@
|
||||
resource "proxmox_virtual_environment_download_file" "talos-cloudimg" {
|
||||
content_type = "iso"
|
||||
datastore_id = "local"
|
||||
file_name = "talos-v1.11.1-nocloud-amd64.iso"
|
||||
node_name = var.proxmox_node_name
|
||||
url = "https://factory.talos.dev/image/ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515/v1.11.1/nocloud-amd64.iso"
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "kube" {
|
||||
name = "kube-${var.proxmox_node_name}"
|
||||
description = "Kubernetes Talos Linux"
|
||||
tags = ["kubernetes", "talos", "terraform"]
|
||||
|
||||
node_name = var.proxmox_node_name
|
||||
vm_id = 702
|
||||
machine = "q35"
|
||||
keyboard_layout = "fr"
|
||||
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
stop_on_destroy = true
|
||||
|
||||
cpu {
|
||||
cores = 40
|
||||
sockets = 2
|
||||
type = "host"
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = 32768
|
||||
floating = 32768
|
||||
}
|
||||
|
||||
boot_order = ["scsi0", "ide0"]
|
||||
scsi_hardware = "virtio-scsi-single"
|
||||
|
||||
cdrom {
|
||||
file_id = proxmox_virtual_environment_download_file.talos-cloudimg.id
|
||||
interface = "ide0"
|
||||
}
|
||||
|
||||
disk {
|
||||
interface = "scsi0"
|
||||
iothread = true
|
||||
datastore_id = "local-lvm"
|
||||
size = 128
|
||||
discard = "ignore"
|
||||
file_format = "raw"
|
||||
}
|
||||
|
||||
vga {
|
||||
type = "serial0"
|
||||
}
|
||||
|
||||
initialization {
|
||||
datastore_id = "local-lvm"
|
||||
interface = "ide2"
|
||||
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "dhcp"
|
||||
}
|
||||
}
|
||||
|
||||
user_account {
|
||||
keys = [trimspace(var.ssh_public_key)]
|
||||
password = var.machine_root_password
|
||||
username = "root"
|
||||
}
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
ipv4_addresses, ipv6_addresses, network_interface_names
|
||||
]
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
model = "virtio"
|
||||
# mac_address = "BC:24:11:F6:E1:C9"
|
||||
vlan_id = 2
|
||||
}
|
||||
|
||||
operating_system {
|
||||
type = "l26"
|
||||
}
|
||||
|
||||
tpm_state {
|
||||
version = "v2.0"
|
||||
}
|
||||
|
||||
serial_device {}
|
||||
}
|
||||
18
infra/r740/proxmox/main.tf
Normal file
18
infra/r740/proxmox/main.tf
Normal file
@@ -0,0 +1,18 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "bpg/proxmox"
|
||||
version = "0.81.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "proxmox" {
|
||||
endpoint = "https://${var.proxmox_host}:8006/"
|
||||
api_token = var.proxmox_api_token
|
||||
insecure = true
|
||||
ssh {
|
||||
agent = true
|
||||
username = "root"
|
||||
}
|
||||
}
|
||||
29
infra/r740/proxmox/variables.tf
Normal file
29
infra/r740/proxmox/variables.tf
Normal file
@@ -0,0 +1,29 @@
|
||||
variable "proxmox_host" {
|
||||
description = "Hostname of Proxmox server"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "proxmox_node_name" {
|
||||
description = "Name of Proxmox node to use"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "proxmox_api_token" {
|
||||
description = "Token to connect Proxmox API"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "machine_root_password" {
|
||||
description = "Root password for VMs and containers"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ssh_public_key" {
|
||||
description = "Public SSH key authorized access for VMs and containers"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ssh_secondary_key" {
|
||||
description = "Secondary SSH key for authorized access to specific VMs and containers"
|
||||
type = string
|
||||
}
|
||||
Reference in New Issue
Block a user