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.lock.hcl
terraform.tfvars
*.tfstate
*.tfstate*
+47 -25
View File
@@ -2,16 +2,19 @@ terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "0.111.1"
version = "0.114.0"
}
}
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 "local" {
path = "terraform.tfstate"
}
# 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" {
@@ -27,19 +30,36 @@ locals {
vmid = v.vmid
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 : {
name = lookup(net, "name", "eth0")
bridge = lookup(net, "bridge", "vmbr0")
vlan_id = net.vlan_id == null ? (floor(v.vmid / 100) % 100) : net.vlan_id
hwaddr = lookup(net, "hwaddr", null)
firewall = lookup(net, "firewall", true)
}
] : []
name = net.name
bridge = net.bridge
vlan_id = net.vlan_id == 0 ? null : net.vlan_id
hwaddr = net.hwaddr
firewall = net.firewall
}
]
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"
dns = {
domain = try(v.dns.domain, null) != null ? v.dns.domain : "lan"
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
swap = v.swap
@@ -76,10 +96,10 @@ resource "proxmox_virtual_environment_container" "all_containers" {
}
dynamic "dns" {
for_each = each.value.nameserver != null ? [1] : []
for_each = each.value.dns.servers != null ? [1] : []
content {
servers = [each.value.nameserver]
domain = "lan"
servers = each.value.dns.servers
domain = each.value.dns.domain
}
}
}
@@ -154,8 +174,10 @@ resource "proxmox_virtual_environment_container" "all_containers" {
started = each.value.started
start_on_boot = each.value.start_on_boot
tags = each.value.tags
}
#output "containers_info" {
# value = local.processed_containers
#}
lifecycle {
ignore_changes = [
operating_system[0].template_file_id,
]
}
}
+383 -138
View File
@@ -1,147 +1,392 @@
variable "proxmox_api_token" {
type = string
sensitive = true
type = string
sensitive = true
}
variable "proxmox_root_password" {
type = string
sensitive = true
type = string
sensitive = true
}
variable "containers" {
type = map(object({
vmid = number
memory = optional(number, 128)
swap = optional(number, 64)
cores = optional(number, 1)
size = optional(number, 1)
started = optional(bool, true)
start_on_boot = optional(bool, true)
unprivileged = optional(bool, true)
ip = optional(string, null)
gw = optional(string)
nameserver = optional(string)
tags = optional(list(string), [])
networks = optional(list(object({
name = optional(string, "eth0")
bridge = optional(string, "vmbr0")
vlan_id = optional(number)
hwaddr = optional(string)
firewall = optional(bool, false)
})), [])
features = optional(object({
fuse = optional(bool, false)
keyctl = optional(bool, false)
mknod = optional(bool, false)
nesting = optional(bool, true)
mount = optional(list(string), [])
}), {
fuse = false
keyctl = false
mknod = false
nesting = true
mount = []
})
mount_point = optional(list(object({
volume = string
size = optional(number)
path = string
})), [])
device_passthrough = optional(list(object({
path = string
gid = optional(number, 0)
uid = optional(number, 0)
mode = optional(string, "0660")
deny_write = optional(bool, false)
})), [])
operating_system = optional(object({
type = optional(string, "alpine")
template_file_id = optional(string, "")
}), {
type = "alpine"
template_file_id = ""
})
}))
default = {
"router" = {
vmid = 101
memory = 1024
swap = 128
cores = 1
size = 2
tags = ["main"]
started = true
start_on_boot = true
ip = ""
networks = [
{
name = "eth0"
bridge = "vmbr0"
firewall = false
vlan_id = 0
hwaddr = "bc:24:11:2f:fa:f6"
},
{
name = "eth1"
bridge = "vmbr1"
firewall = false
vlan_id = 0
hwaddr = "bc:24:11:dd:b3:08"
type = map(object({
vmid = number
auto_network = optional(bool, true)
memory = optional(number, 512)
swap = optional(number, 256)
cores = optional(number, 2)
size = optional(number, 2)
started = optional(bool, true)
start_on_boot = optional(bool, true)
unprivileged = optional(bool, true)
ip = optional(string, null)
gw = optional(string)
nameserver = optional(string)
tags = optional(list(string), [])
networks = optional(list(object({
name = optional(string, "eth0")
bridge = optional(string, "vmbr0")
vlan_id = optional(number)
hwaddr = optional(string)
firewall = optional(bool, false)
})), [{}])
features = optional(object({
fuse = optional(bool, false)
keyctl = optional(bool, false)
mknod = optional(bool, false)
nesting = optional(bool, true)
mount = optional(list(string), [])
}), {
fuse = false
keyctl = false
mknod = false
nesting = true
mount = []
})
dns = optional(object({
domain = optional(string)
servers = optional(list(string))
}), {})
mount_point = optional(list(object({
volume = string
size = optional(number)
path = string
})), [])
device_passthrough = optional(list(object({
path = string
gid = optional(number, 0)
uid = optional(number, 0)
mode = optional(string, "0660")
deny_write = optional(bool, false)
})), [])
operating_system = optional(object({
type = optional(string, "alpine")
template_file_id = optional(string, "")
}), {
type = "alpine"
template_file_id = ""
})
}))
default = {
"router" = {
vmid = 1001
auto_network = false
tags = ["infra","network"]
started = true
start_on_boot = true
networks = [
{
name = "eth0"
bridge = "vmbr0"
firewall = false
vlan_id = 0
hwaddr = "bc:24:11:2f:fa:f6"
},
{
name = "eth1"
bridge = "vmbr1"
firewall = false
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"
}
]
}
]
operating_system = {
type = "debian",
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
"nginx" = {
vmid = 1010
tags = ["infra","web"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
template_file_id = "local:vztmpl/debian-13-standard_13.6-1_amd64.tar.zst"
}
}
"coturn" = {
vmid = 1011
tags = ["infra","network"]
started = true
start_on_boot = true
operating_system = {
type = "debian",
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" }
# ]
#}
}
}