Создал модуль lxc_container в terraform для создания LXC контейнера в proxmox. В итоге при выполнении terrafrom создается ВМ с ОС ubuntu из шаблона контейнера (собран шаблон контейнера вручную с внесенными изменениями). С настроенной сетью, включенным SSH доступом root. В основном main.tf подключается сам модуль и указываются переменные. В provider.tf указывается плагин провайдера для работы с proxmox - telmate/proxmox и его версия. А также настройки для подключения к proxmox. В terraform.tfvars указывается переменная окружения (для прода лучше использовать переменные окружения CI либо vault). В variables.tf происходит инициализация переменной окружения. В modules/lxc_container/main.tf прописывается шаблон создания LXC контейнера ВМ в proxmox. В modules/lxc_container/outputs.tf выходные данные, которые нужно передать из модуля в основной файл main. В modules/lxc_container/variables.tf происходит инициализация переменных, которые передаются из основного main в модуль. Создан модуль modules/lxc_dynamic для создания нескольких ВМ используя for_each. ``` andy@mercower:~/terraform-proxmox$ terraform plan module.app.proxmox_lxc.app_container: Refreshing state... [id=px/lxc/100] Note: Objects have changed outside of Terraform Terraform detected the following changes made outside of Terraform since the last "terraform apply" which may have affected this plan: # module.app.proxmox_lxc.app_container has been deleted - resource "proxmox_lxc" "app_container" { - hostname = "app-01" -> null id = "px/lxc/100" tags = null # (35 unchanged attributes hidden) # (2 unchanged blocks hidden) } Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes. ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # module.app.proxmox_lxc.app_container will be created + resource "proxmox_lxc" "app_container" { + arch = "amd64" + cmode = "tty" + console = true + cores = 2 + cpulimit = 0 + cpuunits = 1024 + current_node = (known after apply) + hostname = "app-01" + id = (known after apply) + memory = 2048 + onboot = false + ostemplate = "local:vztmpl/ubuntu-22.04-custome.tar.zst" + ostype = (known after apply) + password = (sensitive value) + protection = false + ssh_public_keys = <<-EOT ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc EOT + start = true + swap = 512 + target_node = "px" + tty = 2 + unprivileged = false + unused = (known after apply) + vmid = (known after apply) + network { + bridge = "vmbr1" + firewall = true + gw = "10.10.10.1" + hwaddr = (known after apply) + id = (known after apply) + ip = "10.10.10.3/24" + name = "eth0" + tag = (known after apply) + trunks = (known after apply) + type = (known after apply) } + rootfs { + size = "8G" + storage = "local" + volume = (known after apply) } } # module.apps.proxmox_lxc.app_container["nginx01"] will be created + resource "proxmox_lxc" "app_container" { + arch = "amd64" + cmode = "tty" + console = true + cores = 2 + cpulimit = 0 + cpuunits = 1024 + current_node = (known after apply) + hostname = "nginx01" + id = (known after apply) + memory = 2048 + onboot = false + ostemplate = "local:vztmpl/ubuntu-22.04-custome.tar.zst" + ostype = (known after apply) + password = (sensitive value) + protection = false + ssh_public_keys = <<-EOT ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc EOT + start = true + swap = 512 + target_node = "px" + tty = 2 + unprivileged = false + unused = (known after apply) + vmid = (known after apply) + network { + bridge = "vmbr1" + firewall = true + gw = "10.10.10.1" + hwaddr = (known after apply) + id = (known after apply) + ip = "10.10.10.5/24" + name = "eth0" + tag = (known after apply) + trunks = (known after apply) + type = (known after apply) } + rootfs { + size = "8G" + storage = "local" + volume = (known after apply) } } # module.apps.proxmox_lxc.app_container["nginx02"] will be created + resource "proxmox_lxc" "app_container" { + arch = "amd64" + cmode = "tty" + console = true + cores = 2 + cpulimit = 0 + cpuunits = 1024 + current_node = (known after apply) + hostname = "nginx02" + id = (known after apply) + memory = 2048 + onboot = false + ostemplate = "local:vztmpl/ubuntu-22.04-custome.tar.zst" + ostype = (known after apply) + password = (sensitive value) + protection = false + ssh_public_keys = <<-EOT ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc EOT + start = true + swap = 512 + target_node = "px" + tty = 2 + unprivileged = false + unused = (known after apply) + vmid = (known after apply) + network { + bridge = "vmbr1" + firewall = true + gw = "10.10.10.1" + hwaddr = (known after apply) + id = (known after apply) + ip = "10.10.10.6/24" + name = "eth0" + tag = (known after apply) + trunks = (known after apply) + type = (known after apply) } + rootfs { + size = "8G" + storage = "local" + volume = (known after apply) } } Plan: 3 to add, 0 to change, 0 to destroy. ```