Add OpenTofu example (#2)

* Add readme

* Add OpenTofu example

---------

Co-authored-by: Fedor Batonogov <f.batonogov@yandex.ru>
This commit is contained in:
github-actions[bot]
2024-04-15 16:32:51 +03:00
committed by GitHub
parent d6e1b85518
commit 873478bdd3
8 changed files with 269 additions and 0 deletions

25
opentofu/test_vm/.terraform.lock.hcl generated Normal file
View File

@@ -0,0 +1,25 @@
# This file is maintained automatically by "tofu init".
# Manual edits may be lost in future updates.
provider "registry.opentofu.org/bpg/proxmox" {
version = "0.53.1"
constraints = ">= 0.53.1"
hashes = [
"h1:MkkMFotq+rW2sdVlqLk0Uu5NaIvMtsHBT5RJDvnM8Hs=",
"zh:0afa2f8a6aab79973ce792001d5a479a596ed81cc4c44b0d60bcef9dfee093c7",
"zh:0e8a2b62fa0e0e5e83420b391d78bd8f4d7fba6d2df52787c4c9469508642252",
"zh:210a672e445d238538109f2894294199438b776ed89b1a8495d83368811e91e0",
"zh:56c26cb77a07278b2468960b035f53ee47067a51309d8945a1f6c01d66e5a50c",
"zh:854c70381decb32f942f7498d2c0bddc11aa80b73c0c32e12ba5f492dd382245",
"zh:85f4450113086b9004d19febef298f7cafb71cb0b550c420c8c28bc1b4186a3a",
"zh:93003276ec5bc2fc830dc165784cc9b32cc8d2aa41ebbb5f00f0ce12802f1ab2",
"zh:933ad1d9062bbdf63481e6d93d045472d09436ec5624651dec97e1229d725963",
"zh:aa64b56e3e13abe7c06ef1e18ac2dfab0cabda3d9e5e0efe24c8ba5a77755a01",
"zh:ad00656559244ad4a867c271b37a1e8bbb57b63681e98565f287e9d583a316bb",
"zh:ca58d28866723552ecf4c50b1271ec2747c61ed812fb791262a5f0e0ace1c9a4",
"zh:d04bffe5df2a03fa4fc6dbb8d24c389ac8510cc2ed2659dcf57bce3ede0b7809",
"zh:e5fa0efaf38602b4567b0dff3ea334d8b7b618cd15f4f30ca4b332b9a12aacf4",
"zh:f049e50b7f40d678d3e312fb7f837cb46047a8ce27500c7f56e53ecd0fda7e5c",
"zh:f26e0763dbe6a6b2195c94b44696f2110f7f55433dc142839be16b9697fa5597",
]
}

View File

@@ -0,0 +1,4 @@
output "ip_address_vm_01" {
description = "IP адрес vm-01"
value = proxmox_virtual_environment_vm.vm-01.ipv4_addresses[1]
}

View File

@@ -0,0 +1,17 @@
terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = ">= 0.53.1"
}
}
}
provider "proxmox" {
endpoint = var.virtual_environment_endpoint
api_token = var.virtual_environment_api_token
insecure = true
ssh {
agent = false
}
}

View File

@@ -0,0 +1,2 @@
virtual_environment_api_token = "root@pam!for-terraform-provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
virtual_environment_endpoint = "https://x.x.x.x:8006/"

View File

@@ -0,0 +1,9 @@
variable "virtual_environment_endpoint" {
type = string
description = "The endpoint for the Proxmox Virtual Environment API (example: https://host:port)"
}
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)"
}

66
opentofu/test_vm/vm-01.tf Normal file
View File

@@ -0,0 +1,66 @@
# Машинка
resource "proxmox_virtual_environment_vm" "vm-01" {
name = "vm-01"
description = "Managed by OpenTofu"
tags = ["opentofu", "test"]
on_boot = true
# Указываем целевой узел, на котором будет запущена ВМ
node_name = "pve-01"
# Шоблон из которого будет создавать ВМ
clone {
vm_id = "9000"
node_name = "pve-01"
retries = 2
}
# Активируем QEMU для этов ВМ
agent {
enabled = true
}
operating_system {
type = "l26"
}
cpu {
cores = 4
type = "host"
numa = true
}
memory {
dedicated = 4096
}
disk {
size = "40"
interface = "virtio0"
datastore_id = "proxmox-data-02"
file_format = "raw"
}
network_device {
bridge = "vmbr0"
model = "virtio"
}
initialization {
datastore_id = "proxmox-data-02"
ip_config {
ipv4 {
address = "dhcp"
}
}
dns {
servers = ["77.88.8.8"]
}
user_account {
username = "infra"
keys = [
"ssh-rsa..."
]
}
}
}