deploy first 3 node to pve

This commit is contained in:
Антон Прокопенко
2026-09-25 11:43:00 +03:00
parent d3fcf8fb39
commit 97e0dd9c4a
12 changed files with 419 additions and 2 deletions
+91
View File
@@ -0,0 +1,91 @@
resource "proxmox_virtual_environment_vm" "this" {
name = var.name
vm_id = var.vm_id
node_name = var.node_name
pool_id = var.pool_id
description = "Managed by Terraform (ceph course)"
# Proxmox хранит теги отсортированными, иначе будет вечный diff
tags = sort(distinct(var.tags))
clone {
vm_id = var.template_vm_id
datastore_id = var.datastore_id
full = true
}
# Стенд включаем вручную, не при загрузке хоста
on_boot = false
stop_on_destroy = true
agent {
enabled = true
trim = true
wait_for_ip {
ipv4 = true
}
}
cpu {
cores = var.cores
type = "host"
}
# Без ballooning: Ceph плохо переносит, когда у него забирают память
memory {
dedicated = var.memory
}
operating_system {
type = "l26"
}
scsi_hardware = "virtio-scsi-single"
# Системный диск из шаблона, увеличиваем до нужного размера
disk {
interface = "scsi0"
datastore_id = var.datastore_id
size = var.os_disk_size
discard = "on"
iothread = true
ssd = true
}
# Пустые диски под OSD. Serial osdN виден в ВМ в `lsblk -o NAME,SERIAL`
dynamic "disk" {
for_each = range(var.osd_disks)
content {
interface = "scsi${disk.value + 1}"
datastore_id = var.datastore_id
size = var.osd_disk_size
discard = "on"
iothread = true
ssd = true
serial = "osd${disk.value}"
}
}
network_device {
bridge = var.bridge
}
initialization {
datastore_id = var.datastore_id
dns {
servers = var.dns_servers
}
ip_config {
ipv4 {
address = var.ipv4_address
gateway = var.ipv4_gateway
}
}
user_account {
username = var.ssh_user
keys = var.ssh_public_keys
}
}
}
+12
View File
@@ -0,0 +1,12 @@
output "name" {
value = proxmox_virtual_environment_vm.this.name
}
output "vm_id" {
value = proxmox_virtual_environment_vm.this.vm_id
}
output "ipv4" {
description = "Адрес без префикса, для inventory"
value = split("/", var.ipv4_address)[0]
}
+87
View File
@@ -0,0 +1,87 @@
variable "name" {
description = "Имя ВМ (оно же hostname)"
type = string
}
variable "vm_id" {
description = "VMID в Proxmox"
type = number
}
variable "node_name" {
description = "Узел Proxmox, на котором создаётся ВМ"
type = string
}
variable "template_vm_id" {
description = "VMID cloud-init шаблона, из которого клонируется ВМ"
type = number
}
variable "pool_id" {
description = "Пул Proxmox, в который попадает ВМ"
type = string
}
variable "datastore_id" {
description = "Хранилище для дисков ВМ и cloud-init диска"
type = string
}
variable "cores" {
type = number
}
variable "memory" {
description = "RAM в MiB"
type = number
}
variable "os_disk_size" {
description = "Размер системного диска, GB"
type = number
default = 40
}
variable "osd_disks" {
description = "Количество пустых дисков под OSD"
type = number
default = 0
}
variable "osd_disk_size" {
description = "Размер каждого диска под OSD, GB"
type = number
default = 40
}
variable "bridge" {
type = string
default = "vmbr0"
}
variable "ipv4_address" {
description = "Статический адрес в CIDR, например 192.168.3.201/24"
type = string
}
variable "ipv4_gateway" {
type = string
}
variable "dns_servers" {
type = list(string)
}
variable "ssh_user" {
type = string
}
variable "ssh_public_keys" {
type = list(string)
}
variable "tags" {
type = list(string)
default = []
}
+10
View File
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.9"
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "~> 0.114"
}
}
}