mirror of
https://github.com/batonogov/learn-devops.git
synced 2025-11-29 00:33:02 +00:00
Добавлен счетчик для создания подобных ресурсов (#9)
Co-authored-by: Fedor Batonogov <f.batonogov@yandex.ru>
This commit is contained in:
committed by
GitHub
parent
946cde1ea6
commit
a327438868
32
opentofu/test_vm/.terraform.lock.hcl
generated
32
opentofu/test_vm/.terraform.lock.hcl
generated
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ..."
|
||||
|
||||
@@ -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 ...)"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user