diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 2a7411b..29335f4 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -1,24 +1,25 @@ # This file is maintained automatically by "tofu init". # Manual edits may be lost in future updates. -provider "registry.opentofu.org/telmate/proxmox" { - version = "2.9.14" - constraints = "2.9.14" +provider "registry.opentofu.org/bpg/proxmox" { + version = "0.84.1" + constraints = "0.84.1" hashes = [ - "h1:H/f+LbVyPOLslHLAYnGuMMRqWFZ65K6E3V+MCYgfAyk=", - "zh:0d049d33f705e5b814d30028770c084151218439424e99684ce31d7e26a720b5", - "zh:20b1c64ed56d81de95f3f37b82b45b4654c0de26670c0e87a474c5cce13cd015", - "zh:2946058abd1d8e50e475b9ec39781eb02576b40dbd80f4653fade4493a4514c6", - "zh:29e50a25c456f040ce072f23ac57b5b82ebd3b916ca5ae6688332b5ec62adc4a", - "zh:3612932306ce5f08db94868f526cbb8c56d0d3c6ebe1c11a83f92bbf94354296", - "zh:42d1699b0abebaac82ea5a19f4393541d8bb2741bde204a8ac1028cdc29d1b14", - "zh:5ffd5dc567262eb8aafdf2f6eac63f7f21361da9c5d75a3c36b479638a0001b0", - "zh:6692ef323e3b89de99934ad731f6a1850525bf8142916ae28ea4e4048d73a787", - "zh:a5afc98e9a4038516bb58e788cb77dea67a60dce780dfcd206d7373c5a56b776", - "zh:bf902cded709d84fa27fbf91b589c241f2238a6c4924e4e479eebd74320b93a5", - "zh:cab0e1e72c9cebcf669fc6f35ec28cb8ab2dffb0237afc8860aa40d23bf8a49f", - "zh:e523b99a48beec83d9bc04b2d336266044f9f53514cefb652fe6768611847196", - "zh:f593915e8a24829d322d2eaeedcb153328cf9042f0d84f66040dde1be70ede04", - "zh:fba1aff541133e2129dfda0160369635ab48503d5c44b8407ce5922ecc15d0bd", + "h1:4B66+fe1sdDKKmWgI4hHjNIXnD6ZFUwCsIQl9v5OIO8=", + "zh:0a7dc3cafe57dcc82a70edaa98d0aa1ef1a161ebadc54d92dcf6ba92297eb2fb", + "zh:0fbac5deb7c2e25eb3b6ede554e59ee738eddf0af5054c9501bd762b3b4c3d2f", + "zh:13444dc5d24e7c253c511aba20a35073aff8bcc80384d4346ff5575dfbde57a5", + "zh:3edefb3e74b3f39aa48457691e7ee42870e27629d03487664818ffbc802b6395", + "zh:5c90c847871958e8da0471a0b41e028a608cbe59d3a117bc2a9c36f0f867c35c", + "zh:6cab4b308f207467232fe68b69da65701406aeb7b69502feb4723ec2fc031e9f", + "zh:74a35abfdbda62e120ec60848afcb5b2ceeae2f8a1a413d473bd5c40e6464812", + "zh:83f7812baafdf24bf5ef0b0c51a85cbd051d483691fec34009eaa2b0f9cc9054", + "zh:868d5e9f72f555805648598ca24b9d81f8ac31a5d62734a60fcf7f7dd30090ec", + "zh:a15eb3540381fe81343ea8ab6ea497a5c424f137c86e3fb401d5162c924789b1", + "zh:a670b08bc2098eaf0069fedc054858c31e7542d813b831380bb3da2fea420c07", + "zh:b45a0767ee12e04f6391d1ae143a615d866aa08f803383d6afcae9b838d2804f", + "zh:c90331d0b6cc637779dbc3f0467700050b6313b947e042337a35eb4563c86e11", + "zh:d408e3917ba3eb80528a9714375d831c7b48217bac216bad4161aa430cbb4e93", + "zh:f26e0763dbe6a6b2195c94b44696f2110f7f55433dc142839be16b9697fa5597", ] } diff --git a/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64.lock b/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64.lock deleted file mode 100644 index e69de29..0000000 diff --git a/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/LICENSE b/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/LICENSE deleted file mode 100644 index 57395f1..0000000 --- a/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2017 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/README.md b/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/README.md deleted file mode 100644 index 67e2912..0000000 --- a/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/README.md +++ /dev/null @@ -1,53 +0,0 @@ -[![Build Status](https://travis-ci.com/Telmate/terraform-provider-proxmox.svg?branch=master)](https://travis-ci.com/Telmate/terraform-provider-proxmox) - -# Terraform provider plugin for Proxmox - -This repository provides a Terraform provider for -the [Proxmox virtualization platform](https://pve.proxmox.com/pve-docs/) and exposes Terraform resources to provision -QEMU VMs and LXC Containers. - -## Getting Started - -In order to get started, use [the documentation included in this repository](docs/index.md). The documentation contains -a list of the options for the provider. Moreover, there are some guides available how to combine options and start -specific VMs. - -## Quick Start - -Follow this [install guide](docs/guides/installation.md) to install the plugin. - -## Known Limitations - -* `proxmox_vm_qemu`.`disk`.`size` attribute does not match what is displayed in the Proxmox UI. -* Updates to `proxmox_vm_qemu` resources almost always result as a failed task within the Proxmox UI. This appears to be - harmless and the desired configuration changes do get applied. -* `proxmox_vm_qemu` does not (yet) validate vm names, be sure to only use alphanumeric and dashes otherwise you may get - an opaque 400 Parameter Verification failed (indicating a bad value was sent to proxmox). -* When using the `proxmox_lxc` resource, the provider will crash unless `rootfs` is defined. -* When using the Network Boot mode (PXE), a valid NIC must be defined for the VM, and the boot order must specify network first. - -## Contributing - -When contributing, please also add documentation to help other users. - -### Debugging the provider - -Debugging is available for this provider through the Terraform Plugin SDK versions 2.0.0. Therefore, the plugin can be -started with the debugging flag `--debug`. - -For example (using [delve](https://github.com/go-delve/delve) as Debugger): - -```bash -dlv exec --headless ./terraform-provider-my-provider -- --debug -``` - -For more information about debugging a provider please -see: [Debugger-Based Debugging](https://www.terraform.io/docs/extend/debugging.html#debugger-based-debugging) - -## Useful links - -* [Proxmox](https://www.proxmox.com/en/) -* [Proxmox documentation](https://pve.proxmox.com/pve-docs/) -* [Terraform](https://www.terraform.io/) -* [Terraform documentation](https://www.terraform.io/docs/index.html) -* [Recommended ISO builder](https://github.com/Telmate/terraform-ubuntu-proxmox-iso) diff --git a/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/terraform-provider-proxmox_v2.9.14 b/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/terraform-provider-proxmox_v2.9.14 deleted file mode 100755 index f75e9ec..0000000 Binary files a/.terraform/providers/registry.opentofu.org/telmate/proxmox/2.9.14/linux_amd64/terraform-provider-proxmox_v2.9.14 and /dev/null differ diff --git a/main.tf b/main.tf index e6212fb..4f80eec 100644 --- a/main.tf +++ b/main.tf @@ -1,41 +1,82 @@ terraform { + required_version = ">= 1.0" required_providers { proxmox = { - source = "Telmate/proxmox" - version = "2.9.14" # подбери подходящую версию под твой PVE + source = "bpg/proxmox" + version = "~> 0.84.1" } } } provider "proxmox" { - pm_api_url = var.pm_api_url - pm_api_token_id = var.pm_api_token_id - pm_api_token_secret = var.pm_api_token_secret - pm_tls_insecure = true + endpoint = var.proxmox_api_url + api_token = "${var.proxmox_token_id}=${var.proxmox_token_secret}" + insecure = var.proxmox_tls_insecure } -resource "proxmox_vm_qemu" "vm" { - name = var.name - vmid = var.vmid - target_node = var.target_node - clone = var.clone_template # имя шаблона, если клонируем - os_type = "cloud-init" # если шаблон cloud-init - cores = 2 - sockets = 1 - memory = 2048 - scsihw = "virtio-scsi-single" +data "proxmox_virtual_environment_vms" "all_vms" { + node_name = var.proxmox_node +} - # пример сетевого блока - network { - model = "virtio" - bridge = var.bridge # обычно vmbr0 +#locals { + # template_vms = [ + # for vm in data.proxmox_virtual_environment_vms.all_vms.vms : vm + # if vm.name == var.vm_template + # ] + # template_vm_id = length(local.template_vms) > 0 ? local.template_vms[0].vm_id : null +#} + +resource "proxmox_virtual_environment_vm" "ubuntu_vm" { + name = var.vm_name + node_name = var.proxmox_node + + clone { + vm_id = var.template_vm_id + full = true + } + + # VM Hardware Configuration + cpu { + cores = var.vm_cores + sockets = var.vm_sockets + } + + memory { + dedicated = var.vm_memory + } + + disk { + datastore_id = var.vm_disk_storage + size = var.vm_disk_size + interface = var.vm_disk_type } - # cloud-init параметры (если шаблон cloud-init) - ciuser = var.ci_user - cipassword = var.ci_password - ipconfig0 = var.ipconfig0 # e.g. "ip=192.168.1.50/24,gw=192.168.1.1" или "ip=dhcp" - sshkeys = file(var.ssh_pubkey_path) + agent { + enabled = false + } - # если нужно — можно добавить disk {} или disks {} в зависимости от версии провайдера + # Network Configuration + network_device { + bridge = var.vm_network_bridge + model = var.vm_network_model + } + + # Cloud-Init Configuration + initialization { + user_account { + username = var.vm_ci_user + password = var.vm_ci_password + keys = var.vm_ssh_keys != "" ? [file(var.vm_ssh_keys)] : [] + } + + ip_config { + ipv4 { + address = var.vm_ip_config != "" && var.vm_ip_config != "ip=dhcp" ? split(",", var.vm_ip_config)[0] : "dhcp" + gateway = var.vm_ip_config != "" && var.vm_ip_config != "ip=dhcp" ? split("=", split(",", var.vm_ip_config)[1])[1] : null + } + } + } + + # Tags + tags = split(",", var.vm_tags) } \ No newline at end of file diff --git a/plan.tfplan b/plan.tfplan new file mode 100644 index 0000000..910b744 Binary files /dev/null and b/plan.tfplan differ diff --git a/terraform.tfstate b/terraform.tfstate index 203a34b..bc37aeb 100644 --- a/terraform.tfstate +++ b/terraform.tfstate @@ -1 +1 @@ -{"version":4,"terraform_version":"1.10.6","serial":1,"lineage":"d2fc70f5-e0ee-8709-b79a-d28d174cd0ba","outputs":{},"resources":[],"check_results":null} +{"version":4,"terraform_version":"1.10.6","serial":4,"lineage":"d2fc70f5-e0ee-8709-b79a-d28d174cd0ba","outputs":{},"resources":[{"mode":"data","type":"proxmox_virtual_environment_vms","name":"all_vms","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"schema_version":0,"attributes":{"filter":null,"id":"fad70ad1-62e1-4904-817c-47e1043c8138","node_name":"nexus","tags":null,"vms":[{"name":"pz","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":100},{"name":"7days","node_name":"nexus","status":"stopped","tags":[],"template":false,"vm_id":101},{"name":"Mine","node_name":"nexus","status":"stopped","tags":[],"template":false,"vm_id":102},{"name":"nc","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":103},{"name":"NgimxProxy","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":104},{"name":"n8n","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":106},{"name":"vaultwarden","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":108},{"name":"Forgejo","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":110},{"name":"ansible","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":111},{"name":"VM 113","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":113},{"name":"cloud-init-ubuntu","node_name":"nexus","status":"stopped","tags":[],"template":true,"vm_id":115}]},"sensitive_attributes":[]}]},{"mode":"managed","type":"proxmox_virtual_environment_vm","name":"ubuntu_vm","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"schema_version":0,"attributes":{"acpi":true,"agent":[{"enabled":false,"timeout":"15m","trim":false,"type":"virtio"}],"amd_sev":[],"audio_device":[],"bios":"seabios","boot_order":null,"cdrom":[],"clone":[{"datastore_id":"","full":true,"node_name":"","retries":1,"vm_id":115}],"cpu":[{"affinity":"","architecture":"","cores":2,"flags":null,"hotplugged":0,"limit":0,"numa":false,"sockets":1,"type":"qemu64","units":1024}],"description":null,"disk":[{"aio":"io_uring","backup":true,"cache":"none","datastore_id":"local-lvm","discard":"ignore","file_format":"raw","file_id":"","import_from":"","interface":"scsi0","iothread":false,"path_in_datastore":"vm-114-disk-1","replicate":true,"serial":"","size":100,"speed":[],"ssd":false}],"efi_disk":[],"hook_script_file_id":null,"hostpci":[],"id":"114","initialization":[{"datastore_id":"local-lvm","dns":[],"interface":"ide2","ip_config":[{"ipv4":[{"address":"dhcp","gateway":""}],"ipv6":[]}],"meta_data_file_id":"","network_data_file_id":"","type":"","user_account":[{"keys":[],"password":"**********","username":"ubuntu"}],"user_data_file_id":"","vendor_data_file_id":""}],"ipv4_addresses":[],"ipv6_addresses":[],"keyboard_layout":"en-us","kvm_arguments":null,"mac_addresses":["BC:24:11:D0:41:DF"],"machine":null,"memory":[{"dedicated":2048,"floating":0,"hugepages":"","keep_hugepages":false,"shared":0}],"migrate":false,"name":"ubuntutest01","network_device":[{"bridge":"vmbr0","disconnected":false,"enabled":true,"firewall":false,"mac_address":"BC:24:11:D0:41:DF","model":"virtio","mtu":0,"queues":0,"rate_limit":0,"trunks":"","vlan_id":0}],"network_interface_names":[],"node_name":"nexus","numa":[],"on_boot":true,"operating_system":[],"pool_id":null,"protection":false,"reboot":false,"reboot_after_update":true,"rng":[],"scsi_hardware":"virtio-scsi-pci","serial_device":[],"smbios":[],"started":true,"startup":[],"stop_on_destroy":false,"tablet_device":true,"tags":["production","terraform","ubuntu"],"template":false,"timeout_clone":1800,"timeout_create":1800,"timeout_migrate":1800,"timeout_move_disk":1800,"timeout_reboot":1800,"timeout_shutdown_vm":1800,"timeout_start_vm":1800,"timeout_stop_vm":300,"tpm_state":[],"usb":[],"vga":[{"clipboard":"","memory":16,"type":"serial0"}],"virtiofs":[],"vm_id":114,"watchdog":[]},"sensitive_attributes":[[{"type":"get_attr","value":"initialization"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"user_account"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"password"}]],"private":"bnVsbA=="}]}],"check_results":[{"object_kind":"var","config_addr":"var.vm_name","status":"pass","objects":[{"object_addr":"var.vm_name","status":"pass"}]},{"object_kind":"var","config_addr":"var.vm_qemu_agent","status":"pass","objects":[{"object_addr":"var.vm_qemu_agent","status":"pass"}]},{"object_kind":"var","config_addr":"var.vm_memory","status":"pass","objects":[{"object_addr":"var.vm_memory","status":"pass"}]},{"object_kind":"var","config_addr":"var.vm_sockets","status":"pass","objects":[{"object_addr":"var.vm_sockets","status":"pass"}]},{"object_kind":"var","config_addr":"var.vm_cores","status":"pass","objects":[{"object_addr":"var.vm_cores","status":"pass"}]}]} diff --git a/terraform.tfstate.backup b/terraform.tfstate.backup new file mode 100644 index 0000000..bae04c8 --- /dev/null +++ b/terraform.tfstate.backup @@ -0,0 +1 @@ +{"version":4,"terraform_version":"1.10.6","serial":3,"lineage":"d2fc70f5-e0ee-8709-b79a-d28d174cd0ba","outputs":{},"resources":[{"mode":"data","type":"proxmox_virtual_environment_vms","name":"all_vms","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"schema_version":0,"attributes":{"filter":null,"id":"170371fe-90c2-428b-8395-9a18b3639264","node_name":"nexus","tags":null,"vms":[{"name":"pz","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":100},{"name":"7days","node_name":"nexus","status":"stopped","tags":[],"template":false,"vm_id":101},{"name":"Mine","node_name":"nexus","status":"stopped","tags":[],"template":false,"vm_id":102},{"name":"nc","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":103},{"name":"NgimxProxy","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":104},{"name":"n8n","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":106},{"name":"vaultwarden","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":108},{"name":"Forgejo","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":110},{"name":"ansible","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":111},{"name":"VM 113","node_name":"nexus","status":"running","tags":[],"template":false,"vm_id":113},{"name":"cloud-init-ubuntu","node_name":"nexus","status":"stopped","tags":[],"template":true,"vm_id":115}]},"sensitive_attributes":[]}]},{"mode":"managed","type":"proxmox_virtual_environment_vm","name":"ubuntu_vm","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"status":"tainted","schema_version":0,"attributes":{"acpi":true,"agent":[{"enabled":false,"timeout":"15m","trim":false,"type":"virtio"}],"amd_sev":[],"audio_device":[],"bios":"seabios","boot_order":null,"cdrom":[],"clone":[{"datastore_id":"","full":true,"node_name":"","retries":1,"vm_id":115}],"cpu":[{"affinity":"","architecture":"","cores":2,"flags":null,"hotplugged":0,"limit":0,"numa":false,"sockets":1,"type":"qemu64","units":1024}],"description":null,"disk":[{"aio":"io_uring","backup":true,"cache":"none","datastore_id":"local-lvm","discard":"ignore","file_format":"","file_id":"","import_from":"","interface":"scsi","iothread":false,"path_in_datastore":"","replicate":true,"serial":"","size":100,"speed":[],"ssd":false}],"efi_disk":[],"hook_script_file_id":null,"hostpci":[],"id":"114","initialization":[{"datastore_id":"local-lvm","dns":[],"interface":"","ip_config":[{"ipv4":[{"address":"dhcp","gateway":""}],"ipv6":[]}],"meta_data_file_id":"","network_data_file_id":"","type":"","user_account":[{"keys":[],"password":"your-secure-password","username":"ubuntu"}],"user_data_file_id":"","vendor_data_file_id":""}],"ipv4_addresses":null,"ipv6_addresses":null,"keyboard_layout":"en-us","kvm_arguments":null,"mac_addresses":null,"machine":null,"memory":[{"dedicated":2048,"floating":0,"hugepages":"","keep_hugepages":false,"shared":0}],"migrate":false,"name":"ubuntutest01","network_device":[{"bridge":"vmbr0","disconnected":false,"enabled":true,"firewall":false,"mac_address":"","model":"virtio","mtu":0,"queues":0,"rate_limit":0,"trunks":"","vlan_id":0}],"network_interface_names":null,"node_name":"nexus","numa":[],"on_boot":true,"operating_system":[],"pool_id":null,"protection":false,"reboot":false,"reboot_after_update":true,"rng":[],"scsi_hardware":"virtio-scsi-pci","serial_device":[],"smbios":[],"started":true,"startup":[],"stop_on_destroy":false,"tablet_device":true,"tags":["terraform","ubuntu","production"],"template":false,"timeout_clone":1800,"timeout_create":1800,"timeout_migrate":1800,"timeout_move_disk":1800,"timeout_reboot":1800,"timeout_shutdown_vm":1800,"timeout_start_vm":1800,"timeout_stop_vm":300,"tpm_state":[],"usb":[],"vga":null,"virtiofs":[],"vm_id":114,"watchdog":[]},"sensitive_attributes":[[{"type":"get_attr","value":"initialization"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"user_account"},{"type":"index","value":{"value":0,"type":"number"}},{"type":"get_attr","value":"password"}]],"private":"bnVsbA=="}]}],"check_results":[{"object_kind":"var","config_addr":"var.vm_cores","status":"pass","objects":[{"object_addr":"var.vm_cores","status":"pass"}]},{"object_kind":"var","config_addr":"var.vm_name","status":"pass","objects":[{"object_addr":"var.vm_name","status":"pass"}]},{"object_kind":"var","config_addr":"var.vm_sockets","status":"pass","objects":[{"object_addr":"var.vm_sockets","status":"pass"}]},{"object_kind":"var","config_addr":"var.vm_qemu_agent","status":"pass","objects":[{"object_addr":"var.vm_qemu_agent","status":"pass"}]},{"object_kind":"var","config_addr":"var.vm_memory","status":"pass","objects":[{"object_addr":"var.vm_memory","status":"pass"}]}]} diff --git a/terraform.tfvars b/terraform.tfvars index 7667a40..55d7b3b 100644 --- a/terraform.tfvars +++ b/terraform.tfvars @@ -1,3 +1,39 @@ -pm_api_url = "https://192.168.31.30:8006/api2/json" -pm_api_token_id = "tofu@pve!infra" -pm_api_token_secret = "f9f493f5-c6a0-4541-9000-e747d3216516" \ No newline at end of file +# Proxmox API Configuration +proxmox_api_url = "https://192.168.31.30:8006/api2/json" +proxmox_user = "tofu@pve" +proxmox_token_id = "tofu@pve!infra" +proxmox_token_secret = "f9f493f5-c6a0-4541-9000-e747d3216516" +proxmox_tls_insecure = true +proxmox_node = "nexus" + +# VM Template Configuration +vm_template = "115" + +# VM Basic Configuration +vm_name = "ubuntutest01" +vm_cores = 2 +vm_memory = 2048 +vm_sockets = 1 + +# VM Hardware Configuration +vm_boot_order = "order=ide0;net0" +vm_scsihw = "virtio-scsi-pci" +vm_qemu_agent = 1 + +# Network Configuration +vm_network_model = "virtio" +vm_network_bridge = "vmbr0" + +# Disk Configuration +vm_disk_type = "scsi0" +vm_disk_storage = "local-lvm" +vm_disk_size = "100" + +# Cloud-Init Configuration +vm_ci_user = "ubuntu" +vm_ci_password = "your-secure-password" +vm_ip_config = "ip=dhcp" +vm_ssh_keys = "" + +# VM Tags +vm_tags = "terraform,ubuntu,production" \ No newline at end of file diff --git a/variables.tf b/variables.tf index 3ae6545..304426c 100644 --- a/variables.tf +++ b/variables.tf @@ -1,12 +1,222 @@ -variable "pm_api_url" {} -variable "pm_api_token_id" {} -variable "pm_api_token_secret" {} -variable "target_node" { default = "nexus" } -variable "name" { default = "otf-vm-1" } -variable "vmid" { default = 101 } -variable "clone_template" { default = "cloud-init-ubuntu" } -variable "bridge" { default = "vmbr0" } -variable "ci_user" { default = "alex" } -variable "ci_password" { default = "470389" } -variable "ipconfig0" { default = "ip=dhcp" } -variable "ssh_pubkey_path" { default = "~/.ssh/id_rsa.pub" } +# Proxmox Provider Configuration +variable "proxmox_api_url" { + description = "Proxmox API URL" + type = string + default = "https://pve01.cloud.local:8006/api2/json" +} + +variable "proxmox_user" { + description = "Proxmox user for API access" + type = string + default = "terraform@pam" +} + +variable "proxmox_token_id" { + description = "Proxmox API token ID" + type = string + sensitive = true +} + +variable "proxmox_token_secret" { + description = "Proxmox API token secret" + type = string + sensitive = true +} + +variable "proxmox_tls_insecure" { + description = "Skip TLS verification for Proxmox API" + type = bool + default = true +} + +variable "proxmox_node" { + description = "Proxmox node name where VM will be created" + type = string + default = "pve01" +} + +# VM Template Configuration +variable "vm_template" { + description = "Name of the Proxmox template to clone" + type = string + default = "ubuntu-24.04-template" +} + + +# VM Basic Configuration +variable "vm_name" { + description = "Name of the virtual machine" + type = string + default = "ubuntu-cloudinit" + + validation { + condition = length(var.vm_name) > 0 + error_message = "VM name cannot be empty." + } +} + +variable "vm_cores" { + description = "Number of CPU cores for the VM" + type = number + default = 2 + + validation { + condition = var.vm_cores > 0 && var.vm_cores <= 32 + error_message = "VM cores must be between 1 and 32." + } +} + +variable "vm_memory" { + description = "Amount of memory in MB for the VM" + type = number + default = 2048 + + validation { + condition = var.vm_memory >= 512 + error_message = "VM memory must be at least 512 MB." + } +} + +variable "vm_sockets" { + description = "Number of CPU sockets for the VM" + type = number + default = 1 + + validation { + condition = var.vm_sockets > 0 && var.vm_sockets <= 4 + error_message = "VM sockets must be between 1 and 4." + } +} + +# VM Hardware Configuration +variable "vm_boot_order" { + description = "Boot order for the VM" + type = string + default = "order=ide0;net0" +} + +variable "vm_scsihw" { + description = "SCSI hardware type" + type = string + default = "virtio-scsi-pci" +} + +variable "vm_qemu_agent" { + description = "Enable QEMU guest agent" + type = number + default = 1 + + validation { + condition = contains([0, 1], var.vm_qemu_agent) + error_message = "QEMU agent must be 0 (disabled) or 1 (enabled)." + } +} + +# Network Configuration +variable "vm_network_model" { + description = "Network model for the VM" + type = string + default = "virtio" +} + +variable "vm_network_bridge" { + description = "Network bridge for the VM" + type = string + default = "vmbr0" +} + +# Disk Configuration +variable "vm_disk_type" { + description = "Disk type for the VM" + type = string + default = "scsi" +} + +variable "vm_disk_storage" { + description = "Storage location for the VM disk" + type = string + default = "local-lvm" +} + +variable "vm_disk_size" { + description = "Size of the VM disk" + type = string + default = "10G" +} + +# Cloud-Init Configuration +variable "vm_ci_user" { + description = "Cloud-init username" + type = string + default = "ubuntu" +} + +variable "vm_ci_password" { + description = "Cloud-init password" + type = string + sensitive = true + default = "" +} + +variable "vm_ip_config" { + description = "IP configuration for the VM (e.g., 'ip=192.168.1.110/24,gw=192.168.1.1')" + type = string + default = "" +} + +variable "vm_ssh_keys" { + description = "Path to SSH public key file" + type = string + default = "" +} + +variable "vm_tags" { + description = "Tags for the VM" + type = string + default = "terraform,ubuntu" +} + +# Legacy variables (kept for backward compatibility) +variable "ssh_key_path" { + description = "Path to SSH public key file (deprecated, use vm_ssh_keys)" + type = string + default = "~/.ssh/id_rsa.pub" +} + +variable "vm_ip" { + description = "VM IP address (deprecated, use vm_ip_config)" + type = string + default = "" +} + +variable "gateway" { + description = "Gateway IP address (deprecated, use vm_ip_config)" + type = string + default = "" +} + +variable "template_vm_id" { + description = "Gateway Template id" + type = string + default = "115" +} + + +# LXC variables (if needed for future use) +variable "lxc_name" { + description = "Name of the LXC container" + type = string + default = "alpine-lxc" +} + +variable "lxc_template" { + description = "LXC template path" + type = string + default = "local:vztmpl/alpine-3.19-default_20240110_amd64.tar.xz" +} + +variable "lxc_ip" { + description = "LXC container IP address" + type = string + default = "" +} \ No newline at end of file