first add

main
Михаил Ильясов 2025-10-29 20:52:42 +07:00
commit 5eb40abcb0
11 changed files with 765 additions and 0 deletions

24
.terraform.lock.hcl Normal file
View File

@ -0,0 +1,24 @@
# 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-rc05"
constraints = "3.0.2-rc05"
hashes = [
"h1:lHJMTQsDokWsDYmFVCbbe7M0Y2iLH0o7BKmYS7X7bvs=",
"zh:042d748367f33aaf440698644be4f2a2875f9db31915c1ef84616f176fc6174f",
"zh:1488781da1920d60d933c8ce926c34b5e989ffae58e3fbe437973d2b1d2faafc",
"zh:283dd6f74627f1d1d75d616b31f8ced3f97fd5277a07c9535e85cfa765d7a321",
"zh:378f1c2da21aeea083ac2e632db274a02c7a01e2486a40d3c813d05a21142db3",
"zh:38d63d0961f8c32273392caaace30f50cff8ab06e5dda17f67a8827ebffeba98",
"zh:52159782df101ec98f20faff81e8f2d9d92cb4ec903314fcddcc57ec16cdaacb",
"zh:6ca47b90c66b1d2706cb3cbb05da8b3f90a202c4865010202b2962e2b64d217e",
"zh:6e7b85cb2380e4dc0be694dd0e4a24927f7f66df41960eca3cfe907443d4f0b9",
"zh:758775f733673ab5c196db6a33648458037746f94d4bef7ce148cb01474efe2d",
"zh:7c31a3ca6d52db39da2bdd60be37af71d59d808fc206de50fe661535ea436da3",
"zh:af16984350a2f4d77c21f66a479007801e2527543310567c99cd82eb421e249e",
"zh:c1f965d3f96cf3f87af2c12ab9d4bde42f8ef660f8dc34ba3cfc9b20435a7269",
"zh:c2b9022a31103919a5ffbac6ee8d7feb6c4f5f580c1766f769569c2e8e4ce7f1",
"zh:e90162c42f1237323291e3d0de0c62701b3f89350fae18246da06702f41a6123",
]
}

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 <copyright holders>
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.

View File

@ -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)

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 <copyright holders>
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.

View File

@ -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)

236
README.md Normal file
View File

@ -0,0 +1,236 @@
# Terraform + Proxmox Cloud-Init Setup
## Описание
Этот проект демонстрирует, как:
1. Создать **Debian/Ubuntu шаблон** с поддержкой Cloud-Init в Proxmox.
2. Подготовить шаблон для клонирования.
3. Создать виртуальную машину через **Terraform** с использованием шаблона, с настройкой CPU, диска, сети, IP и SSH-ключей.
---
## Шаг 0: Установка Terraform
### Windows
1. Скачайте Terraform: [Terraform Download](https://developer.hashicorp.com/terraform/downloads)
2. Распакуйте архив в удобную папку, например `C:\terraform`
3. Добавьте путь в `PATH`:
```powershell
setx PATH "$env:PATH;C:\terraform"
```
4. Проверьте установку:
```powershell
terraform version
```
## Шаг 1: Создание Cloud-Init шаблона в Proxmox
### 1. Скачивание ISO Debian/Ubuntu
- Скачайте минимальный образ Debian или Ubuntu (например netinst):
- [Debian netinst](https://www.debian.org/distrib/netinst)
- [Ubuntu Server](https://ubuntu.com/download/server)
- Загрузите ISO в Proxmox:
**Datacenter → local → ISO Images → Upload**
---
### 2. Создание новой VM в Proxmox
Пример через CLI:
```bash
qm create 9000 --name "debian-template" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:10
qm set 9000 --ide2 local:iso/debian-13.0.0-amd64-netinst.iso,media=cdrom
qm set 9000 --boot c --bootdisk scsi0
```
Запустите VM и установите минимальную систему Debian/Ubuntu.
---
### 3. Установка Cloud-Init и QEMU Guest Agent
После установки:
```bash
apt update
apt install -y cloud-init qemu-guest-agent
systemctl enable qemu-guest-agent
```
---
### 4. Настройка serial-консоли для Cloud-Init
Чтобы Cloud-Init корректно работал через Proxmox:
```bash
nano /etc/default/grub
```
Измените:
```
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
```
на:
```
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"
```
Применяем:
```bash
update-grub
systemctl enable serial-getty@ttyS0.service
```
---
### 5. Очистка шаблона
```bash
cloud-init clean
apt clean
history -c
poweroff
```
---
### 6. Преобразование VM в шаблон
```bash
qm template 9000
```
Теперь шаблон готов для клонирования.
---
## Шаг 2: Настройка Terraform
### 1. Структура проекта
```
terraform-proxmox/
├── main.tf
├── variables.tf # если используете переменные
└── terraform.tfvars
```
---
### 2. Пример `main.tf`
```hcl
terraform {
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = "3.0.2-rc05"
}
}
}
provider "proxmox" {
pm_tls_insecure = true
pm_api_url = "https://192.168.251.251:8006/api2/json"
pm_user = "terraform@pve"
pm_password = "P@ssw0rd"
}
resource "proxmox_vm_qemu" "vm1" {
name = "terraform-vm1"
description = "Debian VM cloned from Cloud-Init template"
target_node = "pve0"
clone = "debian-template"
# full_clone = true
agent = 1
os_type = "cloud-init"
# CPU and Memory
memory = 4096
scsihw = "virtio-scsi-pci"
bootdisk = "scsi0"
# CPU Block is now REQUIRED[citation:5]
cpu {
type = "host"
cores = 4 # Количество ядер на сокет
sockets = 1
}
# Disks must now be defined in nested `disks` blocks[citation:1][citation:3]
disks {
scsi {
scsi0 {
disk {
size = 20
storage = "ssd1"
}
}
}
ide {
ide3 {
cloudinit {
storage = "ssd1"
}
}
}
}
# Network must be defined in a `network` block with an ID[citation:5]
network {
id = 0 # The network ID is now required and must be in sequence (0, 1, 2...)[citation:5]
model = "virtio"
bridge = "vmbr0"
}
# Cloud-Init
ciuser = "debian"
cipassword = "Password123!"
ipconfig0 = "ip=192.168.251.100/24,gw=192.168.251.254"
serial {
id = 0
type = "socket"
}
# sshkeys = <<EOF
#ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu... user@host
#EOF
}
```
---
### 3. Запуск Terraform
```bash
terraform init
terraform plan
terraform apply
```
После выполнения VM создастся с:
- Настроенным CPU, RAM, диском.
- Cloud-Init: IP, пароль пользователя, SSH ключи.
- Активированным QEMU Guest Agent.
---
## Рекомендации
- Для **нескольких VM** используйте `count` или `for_each` в Terraform.
- Для **динамического IP** можно использовать шаблоны и переменные Terraform.
- Убедитесь, что шаблон **Cloud-Init подготовлен**, иначе VM может не получить IP и SSH.
---

77
main.tf Normal file
View File

@ -0,0 +1,77 @@
terraform {
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = "3.0.2-rc05"
}
}
}
provider "proxmox" {
pm_tls_insecure = true
pm_api_url = "https://192.168.251.251:8006/api2/json"
pm_user = "terraform@pve"
pm_password = "P@ssw0rd"
}
resource "proxmox_vm_qemu" "vm1" {
name = "terraform-vm1"
description = "Debian VM cloned from Cloud-Init template"
target_node = "pve0"
clone = "debian-template"
# full_clone = true
agent = 1
os_type = "cloud-init"
# CPU and Memory
memory = 4096
scsihw = "virtio-scsi-pci"
bootdisk = "scsi0"
# CPU Block is now REQUIRED[citation:5]
cpu {
type = "host"
cores = 4 # Количество ядер на сокет
sockets = 1
}
# Disks must now be defined in nested `disks` blocks[citation:1][citation:3]
disks {
scsi {
scsi0 {
disk {
size = 20
storage = "ssd1"
}
}
}
ide {
ide3 {
cloudinit {
storage = "ssd1"
}
}
}
}
# Network must be defined in a `network` block with an ID[citation:5]
network {
id = 0 # The network ID is now required and must be in sequence (0, 1, 2...)[citation:5]
model = "virtio"
bridge = "vmbr0"
}
# Cloud-Init
ciuser = "debian"
cipassword = "Password123!"
ipconfig0 = "ip=192.168.251.100/24,gw=192.168.251.254"
serial {
id = 0
type = "socket"
}
# sshkeys = <<EOF
#ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu... user@host
#EOF
}

275
terraform.tfstate Normal file
View File

@ -0,0 +1,275 @@
{
"version": 4,
"terraform_version": "1.13.4",
"serial": 17,
"lineage": "e05159d5-9e2a-1f79-ef59-73d54c6e1624",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "proxmox_vm_qemu",
"name": "vm1",
"provider": "provider[\"registry.terraform.io/telmate/proxmox\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"additional_wait": 5,
"agent": 1,
"agent_timeout": 90,
"args": "",
"automatic_reboot": true,
"automatic_reboot_severity": "error",
"balloon": 0,
"bios": "seabios",
"boot": "c",
"bootdisk": "scsi0",
"ci_wait": null,
"cicustom": null,
"cipassword": "Password123!",
"ciupgrade": false,
"ciuser": "debian",
"clone": "debian-template",
"clone_id": null,
"clone_wait": 10,
"cores": 0,
"cpu": [
{
"affinity": "",
"cores": 4,
"flags": [],
"limit": 0,
"numa": false,
"sockets": 1,
"type": "host",
"units": 0,
"vcores": 0
}
],
"cpu_type": "",
"current_node": "pve0",
"default_ipv4_address": "192.168.251.100",
"default_ipv6_address": "",
"define_connection_info": true,
"desc": null,
"description": "Debian VM cloned from Cloud-Init template",
"disk": [],
"disks": [
{
"ide": [
{
"ide0": [],
"ide1": [],
"ide2": [],
"ide3": [
{
"cdrom": [],
"cloudinit": [
{
"storage": "ssd1"
}
],
"disk": [],
"ignore": false,
"passthrough": []
}
]
}
],
"sata": [],
"scsi": [
{
"scsi0": [
{
"cdrom": [],
"cloudinit": [],
"disk": [
{
"asyncio": "",
"backup": true,
"cache": "",
"discard": false,
"emulatessd": false,
"format": "raw",
"id": 1,
"iops_r_burst": 0,
"iops_r_burst_length": 0,
"iops_r_concurrent": 0,
"iops_wr_burst": 0,
"iops_wr_burst_length": 0,
"iops_wr_concurrent": 0,
"iothread": false,
"linked_disk_id": -1,
"mbps_r_burst": 0,
"mbps_r_concurrent": 0,
"mbps_wr_burst": 0,
"mbps_wr_concurrent": 0,
"readonly": false,
"replicate": false,
"serial": "",
"size": "20G",
"storage": "ssd1",
"wwn": ""
}
],
"ignore": false,
"passthrough": []
}
],
"scsi1": [],
"scsi10": [],
"scsi11": [],
"scsi12": [],
"scsi13": [],
"scsi14": [],
"scsi15": [],
"scsi16": [],
"scsi17": [],
"scsi18": [],
"scsi19": [],
"scsi2": [],
"scsi20": [],
"scsi21": [],
"scsi22": [],
"scsi23": [],
"scsi24": [],
"scsi25": [],
"scsi26": [],
"scsi27": [],
"scsi28": [],
"scsi29": [],
"scsi3": [],
"scsi30": [],
"scsi4": [],
"scsi5": [],
"scsi6": [],
"scsi7": [],
"scsi8": [],
"scsi9": []
}
],
"virtio": []
}
],
"efidisk": [],
"force_create": false,
"force_recreate_on_change_of": null,
"full_clone": true,
"hagroup": "",
"hastate": "",
"hostpci": [],
"hotplug": "network,disk,usb",
"id": "pve0/qemu/113",
"ipconfig0": "ip=192.168.251.100/24,gw=192.168.251.254",
"ipconfig1": null,
"ipconfig10": null,
"ipconfig11": null,
"ipconfig12": null,
"ipconfig13": null,
"ipconfig14": null,
"ipconfig15": null,
"ipconfig2": null,
"ipconfig3": null,
"ipconfig4": null,
"ipconfig5": null,
"ipconfig6": null,
"ipconfig7": null,
"ipconfig8": null,
"ipconfig9": null,
"kvm": true,
"linked_vmid": 0,
"machine": "",
"memory": 4096,
"name": "terraform-vm1",
"nameserver": null,
"network": [
{
"bridge": "vmbr0",
"firewall": false,
"id": 0,
"link_down": false,
"macaddr": "bc:24:11:43:6a:e6",
"model": "virtio",
"mtu": 0,
"queues": 0,
"rate": 0,
"tag": 0
}
],
"numa": false,
"onboot": false,
"os_network_config": null,
"os_type": "cloud-init",
"pci": [],
"pcis": [],
"pool": "",
"protection": false,
"pxe": null,
"qemu_os": "other",
"reboot_required": false,
"rng": [],
"scsihw": "virtio-scsi-pci",
"searchdomain": null,
"serial": [
{
"id": 0,
"type": "socket"
}
],
"skip_ipv4": false,
"skip_ipv6": false,
"smbios": [
{
"family": "",
"manufacturer": "",
"product": "",
"serial": "",
"sku": "",
"uuid": "c129fbcc-5ec9-485b-8095-d0e8db7087fd",
"version": ""
}
],
"sockets": 0,
"ssh_forward_ip": null,
"ssh_host": "192.168.251.100",
"ssh_port": "22",
"ssh_private_key": null,
"ssh_user": null,
"sshkeys": null,
"startup": "",
"tablet": true,
"tags": " ",
"target_node": "pve0",
"target_nodes": null,
"timeouts": null,
"tpm_state": [],
"unused_disk": [],
"usb": [],
"usbs": [],
"vcpus": 0,
"vga": [],
"vm_state": "running",
"vmid": 113
},
"sensitive_attributes": [
[
{
"type": "get_attr",
"value": "cipassword"
}
],
[
{
"type": "get_attr",
"value": "ssh_private_key"
}
]
],
"identity_schema_version": 0,
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWZhdWx0IjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInJlYWQiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH19"
}
]
}
],
"check_results": null
}

9
terraform.tfstate.backup Normal file
View File

@ -0,0 +1,9 @@
{
"version": 4,
"terraform_version": "1.13.4",
"serial": 15,
"lineage": "e05159d5-9e2a-1f79-ef59-73d54c6e1624",
"outputs": {},
"resources": [],
"check_results": null
}