add new parameters and hosts

This commit is contained in:
2026-09-07 19:53:00 +00:00
parent 5d9c2d4d8a
commit 9402af23bb
3 changed files with 159 additions and 134 deletions
+1
View File
@@ -1,3 +1,4 @@
.terraform .terraform
.terraform.lock.hcl .terraform.lock.hcl
terraform.tfvars terraform.tfvars
*.tfstate
+128 -128
View File
@@ -1,161 +1,161 @@
terraform { terraform {
required_providers { required_providers {
proxmox = { proxmox = {
source = "bpg/proxmox" source = "bpg/proxmox"
version = "0.111.0" version = "0.111.1"
}
}
backend "http" {
address = "http://10.1.0.104:3000/api/packages/pyrschtjag/terraform/state/runner"
lock_address = "http://10.1.0.104:3000/api/packages/pyrschtjag/terraform/state/runner/lock"
unlock_address = "http://10.1.0.104:3000/api/packages/pyrschtjag/terraform/state/runner/lock"
lock_method = "POST"
unlock_method = "DELETE"
} }
}
backend "http" {
address = "https://gitea.oyacoi.ru/api/packages/pyrschtjag/terraform/state/runner"
lock_address = "https://gitea.oyacoi.ru/api/packages/pyrschtjag/terraform/state/runner/lock"
unlock_address = "https://gitea.oyacoi.ru/api/packages/pyrschtjag/terraform/state/runner/lock"
lock_method = "POST"
unlock_method = "DELETE"
}
} }
provider "proxmox" { provider "proxmox" {
endpoint = "https://firebat.lan:8006/" endpoint = "https://10.1.0.4:8006/"
username = "root@pam" username = "root@pam"
password = var.proxmox_root_password password = var.proxmox_root_password
insecure = true insecure = true
} }
locals { locals {
processed_containers = { processed_containers = {
for k, v in var.containers : k => { for k, v in var.containers : k => {
vmid = v.vmid vmid = v.vmid
tags = v.tags tags = v.tags
networks = length(v.networks) > 0 ? [ networks = length(v.networks) > 0 ? [
for net in v.networks : { for net in v.networks : {
name = lookup(net, "name", "eth0") name = lookup(net, "name", "eth0")
bridge = lookup(net, "bridge", "vmbr0") bridge = lookup(net, "bridge", "vmbr0")
vlan_id = net.vlan_id == null ? (floor(v.vmid / 100) % 100) : net.vlan_id vlan_id = net.vlan_id == null ? (floor(v.vmid / 100) % 100) : net.vlan_id
hwaddr = lookup(net, "hwaddr", null) hwaddr = lookup(net, "hwaddr", null)
firewall = lookup(net, "firewall", true) firewall = lookup(net, "firewall", true)
}
] : []
ip = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.${v.vmid % 100}/24"
gw = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.1"
nameserver = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.1"
memory = v.memory
swap = v.swap
cores = v.cores
size = v.size
started = v.started
start_on_boot = v.start_on_boot
unprivileged = v.unprivileged
features = v.features
mount_point = v.mount_point
device_passthrough = v.device_passthrough
operating_system = v.operating_system
} }
] : []
ip = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.${v.vmid % 100}"
gw = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.1"
nameserver = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.1"
memory = v.memory
swap = v.swap
cores = v.cores
size = v.size
started = v.started
start_on_boot = v.start_on_boot
unprivileged = v.unprivileged
features = v.features
mount_point = v.mount_point
device_passthrough = v.device_passthrough
operating_system = v.operating_system
} }
}
} }
resource "proxmox_virtual_environment_container" "all_containers" { resource "proxmox_virtual_environment_container" "all_containers" {
for_each = local.processed_containers for_each = local.processed_containers
node_name = "firebat" node_name = "firebat"
vm_id = each.value.vmid vm_id = each.value.vmid
initialization { initialization {
hostname = each.key hostname = each.key
dynamic "ip_config" { dynamic "ip_config" {
for_each = each.value.ip != null ? [1] : [] for_each = each.value.ip != null ? [1] : []
content { content {
ipv4 { ipv4 {
address = each.value.ip address = each.value.ip
gateway = each.value.gw gateway = each.value.gw
}
}
}
dynamic "dns" {
for_each = each.value.nameserver != null ? [1] : []
content {
servers = [each.value.nameserver]
domain = "lan"
}
} }
}
} }
dynamic "dns" { cpu {
for_each = each.value.nameserver != null ? [1] : [] #architecture = "amd64"
content { cores = each.value.cores
servers = [each.value.nameserver] #limit = 0
domain = "lan"
}
} }
}
cpu { memory {
#architecture = "amd64" dedicated = each.value.memory
cores = each.value.cores swap = each.value.swap
#limit = 0
}
memory {
dedicated = each.value.memory
swap = each.value.swap
}
dynamic "network_interface" {
for_each = each.value.networks
content {
name = network_interface.value.name
bridge = network_interface.value.bridge
vlan_id = network_interface.value.vlan_id
mac_address = network_interface.value.hwaddr
firewall = network_interface.value.firewall
} }
}
disk { dynamic "network_interface" {
datastore_id = "local-zfs" for_each = each.value.networks
size = each.value.size content {
} name = network_interface.value.name
bridge = network_interface.value.bridge
features { vlan_id = network_interface.value.vlan_id
fuse = each.value.features.fuse mac_address = network_interface.value.hwaddr
keyctl = each.value.features.keyctl firewall = network_interface.value.firewall
mknod = each.value.features.mknod }
nesting = each.value.features.nesting
mount = each.value.features.mount
}
#console {
# enabled = null
# tty_count = null
# type = null
#}
dynamic "mount_point" {
for_each = each.value.mount_point
content {
volume = mount_point.value.volume
size = mount_point.value.size != null ? "${mount_point.value.size}G" : null
path = mount_point.value.path
} }
}
dynamic "device_passthrough" { disk {
for_each = each.value.device_passthrough datastore_id = "local-zfs"
content { size = each.value.size
path = device_passthrough.value.path
gid = device_passthrough.value.gid
uid = device_passthrough.value.uid
mode = device_passthrough.value.mode
deny_write = device_passthrough.value.deny_write
} }
}
operating_system { features {
type = each.value.operating_system.type fuse = each.value.features.fuse
template_file_id = each.value.operating_system.template_file_id keyctl = each.value.features.keyctl
} mknod = each.value.features.mknod
nesting = each.value.features.nesting
mount = each.value.features.mount
}
unprivileged = each.value.unprivileged #console {
started = each.value.started # enabled = null
start_on_boot = each.value.start_on_boot # tty_count = null
tags = each.value.tags # type = null
#}
dynamic "mount_point" {
for_each = each.value.mount_point
content {
volume = mount_point.value.volume
size = mount_point.value.size != null ? "${mount_point.value.size}G" : null
path = mount_point.value.path
}
}
dynamic "device_passthrough" {
for_each = each.value.device_passthrough
content {
path = device_passthrough.value.path
gid = device_passthrough.value.gid
uid = device_passthrough.value.uid
mode = device_passthrough.value.mode
deny_write = device_passthrough.value.deny_write
}
}
operating_system {
type = each.value.operating_system.type
template_file_id = each.value.operating_system.template_file_id
}
unprivileged = each.value.unprivileged
started = each.value.started
start_on_boot = each.value.start_on_boot
tags = each.value.tags
} }
#output "containers_info" { #output "containers_info" {
# value = local.processed_containers # value = local.processed_containers
#} #}
+30 -6
View File
@@ -16,7 +16,7 @@ variable "containers" {
started = optional(bool, true) started = optional(bool, true)
start_on_boot = optional(bool, true) start_on_boot = optional(bool, true)
unprivileged = optional(bool, true) unprivileged = optional(bool, true)
ip = optional(string) ip = optional(string, null)
gw = optional(string) gw = optional(string)
nameserver = optional(string) nameserver = optional(string)
tags = optional(list(string), []) tags = optional(list(string), [])
@@ -61,15 +61,15 @@ variable "containers" {
}) })
})) }))
default = { default = {
"router-test" = { "router" = {
vmid = 100 vmid = 101
memory = 1024 memory = 1024
swap = 128 swap = 128
cores = 1 cores = 1
size = 1 size = 2
tags = ["main"] tags = ["main"]
started = false started = true
start_on_boot = false start_on_boot = true
ip = "" ip = ""
networks = [ networks = [
{ {
@@ -77,12 +77,14 @@ variable "containers" {
bridge = "vmbr0" bridge = "vmbr0"
firewall = false firewall = false
vlan_id = 0 vlan_id = 0
hwaddr = "bc:24:11:2f:fa:f6"
}, },
{ {
name = "eth1" name = "eth1"
bridge = "vmbr1" bridge = "vmbr1"
firewall = false firewall = false
vlan_id = 0 vlan_id = 0
hwaddr = "bc:24:11:dd:b3:08"
} }
] ]
operating_system = { operating_system = {
@@ -90,6 +92,28 @@ variable "containers" {
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst" template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
} }
} }
"steamcmd" = {
vmid = 1203
memory = 6144
swap = 128
cores = 8
size = 2
tags = ["games"]
started = true
start_on_boot = true
networks = [
{
vlan_id = 12
}
]
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/rpool/data/steamcmd/", path = "/mnt/steamcmd/" }
]
}
#"GITEA-TEST" = { #"GITEA-TEST" = {
# vmid = 1012 # vmid = 1012
# memory = 2048 # memory = 2048