add new parameters and hosts

This commit is contained in:
pyrschtjag committed 2026-10-02 21:38:14 +04:00
1 parent 9402af23bb
commit e514045103
3 files changed
+431 -164

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
.terraform .terraform
.terraform.lock.hcl .terraform.lock.hcl
terraform.tfvars terraform.tfvars
*.tfstate *.tfstate*
+47 -25
View File
@@ -2,16 +2,19 @@ terraform {
required_providers { required_providers {
proxmox = { proxmox = {
source = "bpg/proxmox" source = "bpg/proxmox"
version = "0.111.1" version = "0.114.0"
} }
} }
backend "http" { backend "local" {
address = "http://10.1.0.104:3000/api/packages/pyrschtjag/terraform/state/runner" path = "terraform.tfstate"
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 = "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"
# }
} }
provider "proxmox" { provider "proxmox" {
@@ -27,19 +30,36 @@ locals {
vmid = v.vmid vmid = v.vmid
tags = v.tags tags = v.tags
networks = length(v.networks) > 0 ? [ networks = v.auto_network ? [
for network in v.networks : {
name = network.name
bridge = network.bridge
vlan_id = network.vlan_id == null ? (floor(v.vmid / 100) % 100) : (network.vlan_id == 0 ? null : network.vlan_id)
hwaddr = network.hwaddr
firewall = network.firewall
}
] : [
for net in v.networks : { for net in v.networks : {
name = lookup(net, "name", "eth0") name = net.name
bridge = lookup(net, "bridge", "vmbr0") bridge = net.bridge
vlan_id = net.vlan_id == null ? (floor(v.vmid / 100) % 100) : net.vlan_id vlan_id = net.vlan_id == 0 ? null : net.vlan_id
hwaddr = lookup(net, "hwaddr", null) hwaddr = net.hwaddr
firewall = lookup(net, "firewall", true) firewall = net.firewall
} }
] : [] ]
ip = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.${v.vmid % 100}/24" dns = {
gw = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.1" domain = try(v.dns.domain, null) != null ? v.dns.domain : "lan"
nameserver = v.ip == "" ? null : "10.${floor(v.vmid / 100) % 100}.0.1" servers = try(v.dns.servers, null) != null ? v.dns.servers : (
(v.auto_network ? (v.nameserver != null && v.nameserver != "" ? v.nameserver : "10.${floor(v.vmid / 100) % 100}.0.1") : (v.nameserver == "" ? null : v.nameserver)) != null ? [
v.auto_network ? (v.nameserver != null && v.nameserver != "" ? v.nameserver : "10.${floor(v.vmid / 100) % 100}.0.1") : (v.nameserver == "" ? null : v.nameserver)
] : null
)
}
ip = v.auto_network ? (v.ip != null && v.ip != "" ? v.ip : "10.${floor(v.vmid / 100) % 100}.0.${v.vmid % 100}/24") : (v.ip == "" ? null : v.ip)
gw = v.auto_network ? (v.gw != null && v.gw != "" ? v.gw : "10.${floor(v.vmid / 100) % 100}.0.1") : (v.gw == "" ? null : v.gw)
nameserver = v.auto_network ? (v.nameserver != null && v.nameserver != "" ? v.nameserver : "10.${floor(v.vmid / 100) % 100}.0.1") : (v.nameserver == "" ? null : v.nameserver)
memory = v.memory memory = v.memory
swap = v.swap swap = v.swap
@@ -76,10 +96,10 @@ resource "proxmox_virtual_environment_container" "all_containers" {
} }
dynamic "dns" { dynamic "dns" {
for_each = each.value.nameserver != null ? [1] : [] for_each = each.value.dns.servers != null ? [1] : []
content { content {
servers = [each.value.nameserver] servers = each.value.dns.servers
domain = "lan" domain = each.value.dns.domain
} }
} }
} }
@@ -154,8 +174,10 @@ resource "proxmox_virtual_environment_container" "all_containers" {
started = each.value.started started = each.value.started
start_on_boot = each.value.start_on_boot start_on_boot = each.value.start_on_boot
tags = each.value.tags tags = each.value.tags
}
#output "containers_info" { lifecycle {
# value = local.processed_containers ignore_changes = [
#} operating_system[0].template_file_id,
]
}
}
+383 -138
View File
@@ -1,147 +1,392 @@
variable "proxmox_api_token" { variable "proxmox_api_token" {
type = string type = string
sensitive = true sensitive = true
} }
variable "proxmox_root_password" { variable "proxmox_root_password" {
type = string type = string
sensitive = true sensitive = true
} }
variable "containers" { variable "containers" {
type = map(object({ type = map(object({
vmid = number vmid = number
memory = optional(number, 128) auto_network = optional(bool, true)
swap = optional(number, 64) memory = optional(number, 512)
cores = optional(number, 1) swap = optional(number, 256)
size = optional(number, 1) cores = optional(number, 2)
started = optional(bool, true) size = optional(number, 2)
start_on_boot = optional(bool, true) started = optional(bool, true)
unprivileged = optional(bool, true) start_on_boot = optional(bool, true)
ip = optional(string, null) unprivileged = optional(bool, true)
gw = optional(string) ip = optional(string, null)
nameserver = optional(string) gw = optional(string)
tags = optional(list(string), []) nameserver = optional(string)
networks = optional(list(object({ tags = optional(list(string), [])
name = optional(string, "eth0") networks = optional(list(object({
bridge = optional(string, "vmbr0") name = optional(string, "eth0")
vlan_id = optional(number) bridge = optional(string, "vmbr0")
hwaddr = optional(string) vlan_id = optional(number)
firewall = optional(bool, false) hwaddr = optional(string)
})), []) firewall = optional(bool, false)
features = optional(object({ })), [{}])
fuse = optional(bool, false) features = optional(object({
keyctl = optional(bool, false) fuse = optional(bool, false)
mknod = optional(bool, false) keyctl = optional(bool, false)
nesting = optional(bool, true) mknod = optional(bool, false)
mount = optional(list(string), []) nesting = optional(bool, true)
}), { mount = optional(list(string), [])
fuse = false }), {
keyctl = false fuse = false
mknod = false keyctl = false
nesting = true mknod = false
mount = [] nesting = true
}) mount = []
mount_point = optional(list(object({ })
volume = string dns = optional(object({
size = optional(number) domain = optional(string)
path = string servers = optional(list(string))
})), []) }), {})
device_passthrough = optional(list(object({ mount_point = optional(list(object({
path = string volume = string
gid = optional(number, 0) size = optional(number)
uid = optional(number, 0) path = string
mode = optional(string, "0660") })), [])
deny_write = optional(bool, false) device_passthrough = optional(list(object({
})), []) path = string
operating_system = optional(object({ gid = optional(number, 0)
type = optional(string, "alpine") uid = optional(number, 0)
template_file_id = optional(string, "") mode = optional(string, "0660")
}), { deny_write = optional(bool, false)
type = "alpine" })), [])
template_file_id = "" operating_system = optional(object({
}) type = optional(string, "alpine")
})) template_file_id = optional(string, "")
default = { }), {
"router" = { type = "alpine"
vmid = 101 template_file_id = ""
memory = 1024 })
swap = 128 }))
cores = 1 default = {
size = 2 "router" = {
tags = ["main"] vmid = 1001
started = true auto_network = false
start_on_boot = true tags = ["infra","network"]
ip = "" started = true
networks = [ start_on_boot = true
{ networks = [
name = "eth0" {
bridge = "vmbr0" name = "eth0"
firewall = false bridge = "vmbr0"
vlan_id = 0 firewall = false
hwaddr = "bc:24:11:2f:fa:f6" vlan_id = 0
}, hwaddr = "bc:24:11:2f:fa:f6"
{ },
name = "eth1" {
bridge = "vmbr1" name = "eth1"
firewall = false bridge = "vmbr1"
vlan_id = 0 firewall = false
hwaddr = "bc:24:11:dd:b3:08" vlan_id = 0
hwaddr = "bc:24:11:dd:b3:08"
}
]
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
device_passthrough = [
{
path = "/dev/net/tun"
gid = 0
uid = 0
mode = "0660"
}
]
} }
] "nginx" = {
operating_system = { vmid = 1010
type = "debian", tags = ["infra","web"]
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst" started = true
} start_on_boot = true
} operating_system = {
"steamcmd" = { type = "debian",
vmid = 1203 template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
memory = 6144 }
swap = 128 }
cores = 8 "coturn" = {
size = 2 vmid = 1011
tags = ["games"] tags = ["infra","network"]
started = true started = true
start_on_boot = true start_on_boot = true
networks = [ operating_system = {
{ type = "debian",
vlan_id = 12 template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"pgsql" = {
vmid = 1020
tags = ["core","database"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/rpool/data/pgsql/", path = "/mnt/pgsql/" }
]
}
"nfs" = {
vmid = 1021
tags = ["core","storage"]
started = true
start_on_boot = true
unprivileged = false
mount_point = [
{ volume = "/mnt/media1", path = "/mnt/media1" },
{ volume = "/mnt/media2", path = "/mnt/media2" }
]
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"smb-legacy" = {
vmid = 1022
tags = ["core","storage"]
started = true
start_on_boot = true
mount_point = [
{ volume = "/mnt/media1", path = "/mnt/media1" },
{ volume = "/mnt/media2", path = "/mnt/media2" }
]
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"zabbix" = {
vmid = 1030
tags = ["infra","monitoring"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"vaultwarden" = {
vmid = 1110
tags = ["services","security"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/rpool/data/vaultwarden/", path = "/mnt/vaultwarden/" }
]
}
"ntfy" = {
vmid = 1120
tags = ["services","notify"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"prosody" = {
vmid = 1121
tags = ["services","chat"]
started = true
start_on_boot = true
mount_point = [
{ volume = "/rpool/data/prosody", path = "/mnt/prosody" }
]
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"radicale" = {
vmid = 1122
tags = ["services","dav"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/rpool/data/radicale/", path = "/mnt/radicale/" }
]
}
"gitea" = {
vmid = 1123
tags = ["devops","git"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/rpool/data/gitea/", path = "/mnt/gitea/" }
]
}
"runner" = {
vmid = 1124
tags = ["devops","cicd"]
started = true
start_on_boot = true
auto_network = false
ip = "10.1.0.24/24"
gw = "10.1.0.1"
networks = [
{
name = "eth1"
bridge = "vmbr0"
firewall = false
vlan_id = 0
}
]
dns = {
domain = "lan"
servers = ["10.1.0.1"]
}
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"byparr" = {
vmid = 1220
tags = ["media","proxy"]
started = true
start_on_boot = true
memory = 2048
swap = 1024
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"prowlarr" = {
vmid = 1221
tags = ["media","indexer"]
started = true
start_on_boot = true
memory = 1024
swap = 512
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/rpool/data/prowlarr/", path = "/mnt/prowlarr/" }
]
}
"rtorrent" = {
vmid = 1222
tags = ["media","p2p"]
started = true
start_on_boot = true
mount_point = [
{ volume = "/rpool/data/rtorrent", path = "/mnt/rtorrent" },
{ volume = "/mnt/media1", path = "/mnt/media1" },
{ volume = "/mnt/media2", path = "/mnt/media2" }
]
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"slskd" = {
vmid = 1223
tags = ["media","p2p"]
started = true
start_on_boot = true
mount_point = [
{ volume = "/rpool/data/slskd", path = "/mnt/slskd" },
{ volume = "/mnt/media1/", path = "/mnt/media1/" },
]
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"torrserver" = {
vmid = 1224
tags = ["media","streaming"]
started = true
start_on_boot = true
memory = 1024
swap = 512
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"lampa" = {
vmid = 1225
tags = ["media", "streaming"]
started = true
start_on_boot = true
memory = 2048
swap = 1024
size = 4
mount_point = [
{ volume= "/rpool/data/lampa/", path = "/mnt/lampa/" }
]
operating_system = {
type = "debian"
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"asf" = {
vmid = 1230
tags = ["gaming","automation"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/rpool/data/asf/", path = "/mnt/asf/" }
]
}
"ps3netsrv" = {
vmid = 1231
tags = ["gaming","media"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/mnt/media2/", path = "/mnt/media2/" }
]
}
"valheim" = {
vmid = 1232
memory = 4096
swap = 2048
cores = 4
size = 2
tags = ["gaming","server"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
mount_point = [
{ volume= "/rpool/data/valheim/", path = "/mnt/valheim/" }
]
} }
]
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" = {
# vmid = 1012
# memory = 2048
# swap = 1024
# cores = 2
# size = 1
# operating_system = {
# type = "debian",
# template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
# }
# mount_point = [
# { VOLUME = "/RPOOL/DATa/gitea/", path = "/var/lib/gitea/" }
# ]
# }
#"pgsql-test" = {
# vmid = 1011
# memory = 2048
# swap = 1024
# cores = 2
# size = 1
# OPERATING_SYSTEM = {
# type = "debian"
# template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
# }
# mount_point = [
# { volume = "/rpool/data/postgresql/pgdata", path = "/var/lib/postgresql/17/main" },
# { volume = "/rpool/data/postgresql/pgbackup", path = "/var/lib/postgresql/17/backup" }
# ]
#}
}
} }