Создан проект terraform

This commit is contained in:
admin 2026-03-07 17:11:57 +03:00
commit b1f0160bd7
17 changed files with 415 additions and 0 deletions

10
.terraform.lock.hcl generated Normal file
View File

@ -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=",
]
}

View File

@ -0,0 +1 @@
{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"app","Source":"./modules/lxc_container","Dir":"modules/lxc_container"}]}

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)

21
main.tf Normal file
View File

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

View File

@ -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"
}
}

View File

@ -0,0 +1,3 @@
output "vm_hostname" {
value = proxmox_lxc.app_container.hostname
}

View File

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

View File

@ -0,0 +1,8 @@
terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = "3.0.2-rc07"
}
}
}

15
provider.tf Normal file
View File

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

7
ssh/id_terraform Normal file
View File

@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACD4l+WzhF319wL8LLXQMmGB4EshgxddjczgQsHzT0FYKAAAAJB9dIGTfXSB
kwAAAAtzc2gtZWQyNTUxOQAAACD4l+WzhF319wL8LLXQMmGB4EshgxddjczgQsHzT0FYKA
AAAED+NFo9Z3Zoo9k9c3gou33YGmE0/XhdI84dRFJEo0LZR/iX5bOEXfX3AvwstdAyYYHg
SyGDF12NzOBCwfNPQVgoAAAADXRlcnJhZm9ybUBseGM=
-----END OPENSSH PRIVATE KEY-----

1
ssh/id_terraform.pub Normal file
View File

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc

109
terraform.tfstate Normal file
View File

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

109
terraform.tfstate.backup Normal file
View File

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

1
terraform.tfvars Normal file
View File

@ -0,0 +1 @@
pm_token_secret = "e71efc34-8635-41fd-b8e9-019858b451a7"

3
variables.tf Normal file
View File

@ -0,0 +1,3 @@
variable "pm_token_secret" {
description = "Секрет токена Proxmox"
}