From a3274388680308732e75f9a4acb240d8a245102a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 May 2024 15:54:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=81=D1=87=D0=B5=D1=82=D1=87=D0=B8=D0=BA=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D0=BE=D0=B1=D0=BD=D1=8B=D1=85=20=D1=80?= =?UTF-8?q?=D0=B5=D1=81=D1=83=D1=80=D1=81=D0=BE=D0=B2=20(#9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fedor Batonogov --- opentofu/test_vm/.terraform.lock.hcl | 32 +++++++++---------- opentofu/test_vm/output.tf | 9 ++++-- opentofu/test_vm/terraform.tfvars.example | 1 + opentofu/test_vm/variables.tf | 5 +++ opentofu/test_vm/{vm-01.tf => vm.tf} | 38 ++++++++++++++--------- 5 files changed, 52 insertions(+), 33 deletions(-) rename opentofu/test_vm/{vm-01.tf => vm.tf} (55%) diff --git a/opentofu/test_vm/.terraform.lock.hcl b/opentofu/test_vm/.terraform.lock.hcl index f2f1ec4..147a8b9 100644 --- a/opentofu/test_vm/.terraform.lock.hcl +++ b/opentofu/test_vm/.terraform.lock.hcl @@ -2,24 +2,24 @@ # Manual edits may be lost in future updates. provider "registry.opentofu.org/bpg/proxmox" { - version = "0.54.0" + version = "0.58.0" constraints = ">= 0.53.1" hashes = [ - "h1:xgDrDol/cYu93YOPTL0UVpURchPzdxPXaHjcoieoXXI=", - "zh:4521f8893b4645c93e75ffc3545ea59d3f31aed7cea4c26dcd0fbd7c0cce6ca8", - "zh:520e56abd10d888935047ef07a7577c2a1cce5bc54e25b03a0dbdc4356997ca9", - "zh:53469dd058ef8b2ea29577f69a2681f8ffb9f79494b8c1d1594dd42ad314d7bd", - "zh:6948adb6e088fe652b7273906a5c11032528f84eb5a5ca797534ab3b6076a8c6", - "zh:72655e9765b7791e3e37508c70a847172561bff348c7d5f916794e5823a84efe", - "zh:7faa281319d90026ad9b2dce00ac059896f451cb9305ed11bb90fcfda7c5d143", - "zh:8fe20fa893e9545aa30672392f76948ed56a93a2decb1d3bd8693c5e1d2dd85a", - "zh:b175411aa820c1a47473ef691c743670eeb900999576c6cdcb113d14a7c499aa", - "zh:b59205ad7981f263ff287d3eb0a93296f8cd6b166a01ddd3b16606fc39d456ec", + "h1:d5xlm8dyjN15nawV8T2WZ8lklAsgfoDxsKC4R7nXthI=", + "zh:0143133e07418b1c223524fb435fd0067b36bfb737c11feb8ed3942b92852580", + "zh:02f3fff3a1510cf3c539bbedf117e97eb77ce275fb6e1bb0ac9ce83159f66cb1", + "zh:267152be0e04ef0424affa6133aba7fa47097d1e3582147a8058e32be8fb93e4", + "zh:3468091065b325b7d296e11d6eee69bf3e70d7081b983ea9a5dcc39502217066", + "zh:54d238401b162725348ec2c8739a1f2a848e6e3f378e2ede4872905960a64fb5", + "zh:87ac12f607373c591a01b110230dc33a48cbb258e8454103e1a36305985ee006", + "zh:9341cc8d189c3d60a288b6ca0ec245c5346c504d15f90bee2369dec0c35f6a93", + "zh:9bb55512d9d6ef90b8324ace1458c20934188c9b3d5741768bccb08071cf3ca8", + "zh:a596515046a93cbd1205826c0e9a608c6d98040acdd2df29360d832c98ac7c95", + "zh:b1a9167b34cc07bcac2934d815faafb4ed2ee1941b8bcd0a0e5e6a1b5bb32c26", + "zh:bf415c58ff98a63b1953d7f64d826093f64d302bd8467a7ac213a72399c2942c", + "zh:c7f77c63cb995540990d8b5fac2fdd8166bb349d840637197f93635d2d38cc48", + "zh:ead5c17d559937d770734189c8fbf801f999afa26861a992839b737ea65cb89c", "zh:f26e0763dbe6a6b2195c94b44696f2110f7f55433dc142839be16b9697fa5597", - "zh:f3524bc67d995e98ad9d7e17f3be91f7a975608180fad6b227fc42087b5facc1", - "zh:f4bf087717e1b0f5f3ee7d3b6b47fb66e5f821097f15ec0cf6714a39c7d80959", - "zh:fc14a29b1aef50872d60f338af89f7cbbac307c630f973c07a7951bdde8be2a5", - "zh:fc72da3d651bf0f0e20a0860e9217a94797b4c1d5cae1742f1b8e15d28f8ceeb", - "zh:fff2299a427e1590775611bf186220686795af966772e61e44234f0df44b6c22", + "zh:fc60dda187b0d3101108ea9181b6ad765e352e8439fb14855f2838747991dcbc", ] } diff --git a/opentofu/test_vm/output.tf b/opentofu/test_vm/output.tf index 849f955..8578a11 100644 --- a/opentofu/test_vm/output.tf +++ b/opentofu/test_vm/output.tf @@ -1,4 +1,7 @@ -output "ip_address_vm_01" { - description = "IP адрес vm-01" - value = proxmox_virtual_environment_vm.vm-01.ipv4_addresses[1] +output "vm_info" { + description = "Names and IP addresses of the created VMs" + value = { + for i in range(var.vm_count) : + format("vm-%02d", i + 1) => proxmox_virtual_environment_vm.vm[i].ipv4_addresses[1] + } } diff --git a/opentofu/test_vm/terraform.tfvars.example b/opentofu/test_vm/terraform.tfvars.example index c5306f0..e046f62 100644 --- a/opentofu/test_vm/terraform.tfvars.example +++ b/opentofu/test_vm/terraform.tfvars.example @@ -1,2 +1,3 @@ virtual_environment_api_token = "root@pam!for-terraform-provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" virtual_environment_endpoint = "https://x.x.x.x:8006/" +ssh_public_key = "ssh-rsa ..." diff --git a/opentofu/test_vm/variables.tf b/opentofu/test_vm/variables.tf index 4508554..4d3e347 100644 --- a/opentofu/test_vm/variables.tf +++ b/opentofu/test_vm/variables.tf @@ -7,3 +7,8 @@ variable "virtual_environment_api_token" { type = string description = "The api roken the Proxmox Virtual Environment API (example: root@pam!for-terraform-provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)" } + +variable "ssh_public_key" { + type = string + description = "SSH Puclic key for VMs (example: ssh-rsa ...)" +} diff --git a/opentofu/test_vm/vm-01.tf b/opentofu/test_vm/vm.tf similarity index 55% rename from opentofu/test_vm/vm-01.tf rename to opentofu/test_vm/vm.tf index 815faf2..a6345ee 100644 --- a/opentofu/test_vm/vm-01.tf +++ b/opentofu/test_vm/vm.tf @@ -1,22 +1,24 @@ -# Машинка -resource "proxmox_virtual_environment_vm" "vm-01" { - name = "vm-01" +variable "vm_count" { + description = "Number of VMs to create" + default = 2 +} + +resource "proxmox_virtual_environment_vm" "vm" { + count = var.vm_count + name = format("vm-%02d", count.index + 1) migrate = true description = "Managed by OpenTofu" tags = ["opentofu", "test"] on_boot = true - # Указываем целевой узел, на котором будет запущена ВМ - node_name = "pve-01" + node_name = format("pve-%02d", count.index + 1) - # Шоблон из которого будет создавать ВМ clone { - vm_id = "2204" + vm_id = "2404" node_name = "pve-01" retries = 2 } - # Активируем QEMU для этов ВМ agent { enabled = true } @@ -26,19 +28,24 @@ resource "proxmox_virtual_environment_vm" "vm-01" { } cpu { - cores = 4 + cores = 2 type = "host" numa = true } memory { - dedicated = 4096 + dedicated = 2048 + } + + vga { + memory = 4 + type = "serial0" } disk { size = "40" interface = "virtio0" - datastore_id = "proxmox-data-02" + datastore_id = "proxmox-data-01" file_format = "raw" } @@ -48,19 +55,22 @@ resource "proxmox_virtual_environment_vm" "vm-01" { } initialization { - datastore_id = "proxmox-data-02" + datastore_id = "proxmox-data-01" ip_config { ipv4 { address = "dhcp" } } dns { - servers = ["77.88.8.8"] + servers = [ + "77.88.8.8", + "8.8.8.8" + ] } user_account { username = "infra" keys = [ - "ssh-rsa..." + var.ssh_public_key ] } }