commit b1f0160bd77acd764ff5bd0e13ec2cb725cd152c Author: admin Date: Sat Mar 7 17:11:57 2026 +0300 Создан проект terraform diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..e894936 --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,10 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/telmate/proxmox" { + version = "3.0.2-rc07" + constraints = "3.0.2-rc07" + hashes = [ + "h1:zp5hpQJQ4t4zROSLqdltVpBO+Riy9VugtfFbpyTw1aM=", + ] +} diff --git a/.terraform/modules/modules.json b/.terraform/modules/modules.json new file mode 100644 index 0000000..cdb8310 --- /dev/null +++ b/.terraform/modules/modules.json @@ -0,0 +1 @@ +{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"app","Source":"./modules/lxc_container","Dir":"modules/lxc_container"}]} \ No newline at end of file diff --git a/.terraform/providers/registry.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/LICENSE b/.terraform/providers/registry.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/LICENSE new file mode 100644 index 0000000..57395f1 --- /dev/null +++ b/.terraform/providers/registry.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/LICENSE @@ -0,0 +1,21 @@ +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.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/README.md b/.terraform/providers/registry.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/README.md new file mode 100644 index 0000000..eb7c72c --- /dev/null +++ b/.terraform/providers/registry.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/README.md @@ -0,0 +1,51 @@ +[![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. +* 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.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/terraform-provider-proxmox_v3.0.2-rc07 b/.terraform/providers/registry.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/terraform-provider-proxmox_v3.0.2-rc07 new file mode 100755 index 0000000..8b8c70a Binary files /dev/null and b/.terraform/providers/registry.terraform.io/telmate/proxmox/3.0.2-rc07/linux_amd64/terraform-provider-proxmox_v3.0.2-rc07 differ diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..17d9352 --- /dev/null +++ b/main.tf @@ -0,0 +1,21 @@ +module "app" { + source = "./modules/lxc_container" + + target_node = "px" + vm_hostname = "app-01" + ostemplate = "local:vztmpl/ubuntu-22.04-custome.tar.zst" + ssh_public_key = file("./ssh/id_terraform.pub") + private_key = file("./ssh/id_terraform") + ip_address = "10.10.10.3/24" + gateway = "10.10.10.1" + bridge = "vmbr1" + storage = "local" + size = "8G" + + lxc_resources = { + cores = 2 + memory = 2048 + swap = 512 + } + + } diff --git a/modules/lxc_container/main.tf b/modules/lxc_container/main.tf new file mode 100644 index 0000000..2724d8b --- /dev/null +++ b/modules/lxc_container/main.tf @@ -0,0 +1,37 @@ +resource "proxmox_lxc" "app_container" { + target_node = var.target_node + hostname = var.vm_hostname + ostemplate = var.ostemplate + password = "password" + + ssh_public_keys = var.ssh_public_key + + cores = var.lxc_resources.cores + memory = var.lxc_resources.memory + swap = var.lxc_resources.swap + + rootfs { + storage = var.storage + size = var.size + } + + network { + name = "eth0" + bridge = var.bridge + ip = var.ip_address + gw = var.gateway + firewall = true + } + + start = true + + connection { + type = "ssh" + host = var.ip_address + user = "root" + private_key = var.private_key + timeout = "2m" + } + + +} diff --git a/modules/lxc_container/outputs.tf b/modules/lxc_container/outputs.tf new file mode 100644 index 0000000..9c113b7 --- /dev/null +++ b/modules/lxc_container/outputs.tf @@ -0,0 +1,3 @@ +output "vm_hostname" { + value = proxmox_lxc.app_container.hostname +} diff --git a/modules/lxc_container/variables.tf b/modules/lxc_container/variables.tf new file mode 100644 index 0000000..eb6a122 --- /dev/null +++ b/modules/lxc_container/variables.tf @@ -0,0 +1,18 @@ +variable "target_node" {} +variable "vm_hostname" {} +variable "ostemplate" {} +variable "ssh_public_key" {} +variable "private_key" {} +variable "ip_address" {} +variable "gateway" {} +variable "bridge" {} +variable "storage" {} +variable "size" {} + +variable "lxc_resources" { + type = object({ + cores = number + memory = number + swap = number + }) +} diff --git a/modules/lxc_container/versions.tf b/modules/lxc_container/versions.tf new file mode 100644 index 0000000..c540864 --- /dev/null +++ b/modules/lxc_container/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + proxmox = { + source = "telmate/proxmox" + version = "3.0.2-rc07" + } + } +} diff --git a/provider.tf b/provider.tf new file mode 100644 index 0000000..c8effc4 --- /dev/null +++ b/provider.tf @@ -0,0 +1,15 @@ +terraform { + required_providers { + proxmox = { + source = "telmate/proxmox" + version = "3.0.2-rc07" + } + } +} + +provider "proxmox" { + pm_api_url = "https://185.78.29.7:8006/api2/json" + pm_api_token_id = "terraform@pve!tf" + pm_api_token_secret = var.pm_token_secret + pm_tls_insecure = true +} diff --git a/ssh/id_terraform b/ssh/id_terraform new file mode 100644 index 0000000..f957c0d --- /dev/null +++ b/ssh/id_terraform @@ -0,0 +1,7 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW +QyNTUxOQAAACD4l+WzhF319wL8LLXQMmGB4EshgxddjczgQsHzT0FYKAAAAJB9dIGTfXSB +kwAAAAtzc2gtZWQyNTUxOQAAACD4l+WzhF319wL8LLXQMmGB4EshgxddjczgQsHzT0FYKA +AAAED+NFo9Z3Zoo9k9c3gou33YGmE0/XhdI84dRFJEo0LZR/iX5bOEXfX3AvwstdAyYYHg +SyGDF12NzOBCwfNPQVgoAAAADXRlcnJhZm9ybUBseGM= +-----END OPENSSH PRIVATE KEY----- diff --git a/ssh/id_terraform.pub b/ssh/id_terraform.pub new file mode 100644 index 0000000..a1170ca --- /dev/null +++ b/ssh/id_terraform.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 0000000..51150b1 --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,109 @@ +{ + "version": 4, + "terraform_version": "1.14.6", + "serial": 3, + "lineage": "f4c291e8-3767-da71-b85c-0fdc56b7a316", + "outputs": {}, + "resources": [ + { + "module": "module.app", + "mode": "managed", + "type": "proxmox_lxc", + "name": "app_container", + "provider": "provider[\"registry.terraform.io/telmate/proxmox\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arch": "amd64", + "bwlimit": 0, + "clone": null, + "clone_storage": null, + "cmode": "tty", + "console": true, + "cores": 2, + "cpulimit": 0, + "cpuunits": 1024, + "current_node": "px", + "description": "", + "features": [], + "force": false, + "full": null, + "hagroup": "", + "hastate": "", + "hookscript": "", + "hostname": "app-01", + "id": "px/lxc/100", + "ignore_unpack_errors": false, + "lock": "", + "memory": 2048, + "mountpoint": [], + "nameserver": "", + "network": [ + { + "bridge": "vmbr1", + "firewall": true, + "gw": "10.10.10.1", + "gw6": "", + "hwaddr": "BC:24:11:7F:7E:1B", + "id": 0, + "ip": "10.10.10.3/24", + "ip6": "", + "mtu": 0, + "name": "eth0", + "rate": 0, + "tag": 0, + "trunks": "", + "type": "veth" + } + ], + "onboot": false, + "ostemplate": "local:vztmpl/ubuntu-22.04-custome.tar.zst", + "ostype": "ubuntu", + "password": "password", + "pool": null, + "protection": false, + "restore": false, + "rootfs": [ + { + "acl": false, + "quota": false, + "replicate": false, + "ro": false, + "shared": false, + "size": "8G", + "storage": "local", + "volume": "local:100/vm-100-disk-0.raw" + } + ], + "searchdomain": "", + "ssh_public_keys": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc\n", + "start": true, + "startup": "", + "swap": 512, + "tags": "", + "target_node": "px", + "template": false, + "timeouts": null, + "tty": 2, + "unique": false, + "unprivileged": false, + "unused": [], + "vmid": 100 + }, + "sensitive_attributes": [ + [ + { + "type": "get_attr", + "value": "password" + } + ] + ], + "identity_schema_version": 0, + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } + ] + } + ], + "check_results": null +} diff --git a/terraform.tfstate.backup b/terraform.tfstate.backup new file mode 100644 index 0000000..999035e --- /dev/null +++ b/terraform.tfstate.backup @@ -0,0 +1,109 @@ +{ + "version": 4, + "terraform_version": "1.14.6", + "serial": 1, + "lineage": "f4c291e8-3767-da71-b85c-0fdc56b7a316", + "outputs": {}, + "resources": [ + { + "module": "module.app", + "mode": "managed", + "type": "proxmox_lxc", + "name": "app_container", + "provider": "provider[\"registry.terraform.io/telmate/proxmox\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arch": "amd64", + "bwlimit": 0, + "clone": null, + "clone_storage": null, + "cmode": "tty", + "console": true, + "cores": 2, + "cpulimit": 0, + "cpuunits": 1024, + "current_node": "px", + "description": "", + "features": [], + "force": false, + "full": null, + "hagroup": "", + "hastate": "", + "hookscript": "", + "hostname": "app-01", + "id": "px/lxc/100", + "ignore_unpack_errors": false, + "lock": "", + "memory": 2048, + "mountpoint": [], + "nameserver": "", + "network": [ + { + "bridge": "vmbr1", + "firewall": true, + "gw": "10.10.10.1", + "gw6": "", + "hwaddr": "BC:24:11:9A:C9:FA", + "id": 0, + "ip": "10.10.10.3/24", + "ip6": "", + "mtu": 0, + "name": "eth0", + "rate": 0, + "tag": 0, + "trunks": "", + "type": "veth" + } + ], + "onboot": false, + "ostemplate": "local:vztmpl/ubuntu-22.04-custome.tar.zst", + "ostype": "ubuntu", + "password": "password", + "pool": null, + "protection": false, + "restore": false, + "rootfs": [ + { + "acl": false, + "quota": false, + "replicate": false, + "ro": false, + "shared": false, + "size": "8G", + "storage": "local", + "volume": "local:100/vm-100-disk-0.raw" + } + ], + "searchdomain": "", + "ssh_public_keys": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc\n", + "start": true, + "startup": "", + "swap": 512, + "tags": "", + "target_node": "px", + "template": false, + "timeouts": null, + "tty": 2, + "unique": false, + "unprivileged": false, + "unused": [], + "vmid": 100 + }, + "sensitive_attributes": [ + [ + { + "type": "get_attr", + "value": "password" + } + ] + ], + "identity_schema_version": 0, + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19" + } + ] + } + ], + "check_results": null +} diff --git a/terraform.tfvars b/terraform.tfvars new file mode 100644 index 0000000..c6f416c --- /dev/null +++ b/terraform.tfvars @@ -0,0 +1 @@ +pm_token_secret = "e71efc34-8635-41fd-b8e9-019858b451a7" diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..97ead75 --- /dev/null +++ b/variables.tf @@ -0,0 +1,3 @@ +variable "pm_token_secret" { + description = "Секрет токена Proxmox" +}