интеграция OpenTofu с Proxmox
This commit is contained in:
commit
355c256949
34
.terraform.lock.hcl
generated
Normal file
34
.terraform.lock.hcl
generated
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# This file is maintained automatically by "tofu init".
|
||||||
|
# Manual edits may be lost in future updates.
|
||||||
|
|
||||||
|
provider "registry.opentofu.org/bpg/proxmox" {
|
||||||
|
version = "0.98.1"
|
||||||
|
constraints = "0.98.1"
|
||||||
|
hashes = [
|
||||||
|
"h1:/3n9NevrIwRAI/0HOEbeO4uQfCCivjspG8pDgzhqOSU=",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "registry.opentofu.org/hashicorp/local" {
|
||||||
|
version = "2.7.0"
|
||||||
|
constraints = "2.7.0"
|
||||||
|
hashes = [
|
||||||
|
"h1:uWL9nhlxLY2xW3GMh8IFQv0S1UP3HMlN/B+2Nr7fsZE=",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "registry.opentofu.org/hashicorp/random" {
|
||||||
|
version = "3.8.1"
|
||||||
|
constraints = "3.8.1"
|
||||||
|
hashes = [
|
||||||
|
"h1:xX86qU/7e6ep0QoIQPgh4Ho+dKJrgYIJIzzqvVSgYuc=",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "registry.opentofu.org/hashicorp/tls" {
|
||||||
|
version = "4.2.1"
|
||||||
|
constraints = "4.2.1"
|
||||||
|
hashes = [
|
||||||
|
"h1:jNN7/BmtBs6ipjreb8Y+Bc6no/H4GYL0zJ3jEbMDuyI=",
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
/home/andy/.terraform.d/plugins/registry.opentofu.org/bpg/proxmox/0.98.1/linux_amd64
|
||||||
@ -0,0 +1 @@
|
|||||||
|
/home/andy/.terraform.d/plugins/registry.opentofu.org/hashicorp/local/2.7.0/linux_amd64
|
||||||
@ -0,0 +1 @@
|
|||||||
|
/home/andy/.terraform.d/plugins/registry.opentofu.org/hashicorp/random/3.8.1/linux_amd64
|
||||||
@ -0,0 +1 @@
|
|||||||
|
/home/andy/.terraform.d/plugins/registry.opentofu.org/hashicorp/tls/4.2.1/linux_amd64
|
||||||
75
main.tf
Normal file
75
main.tf
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
proxmox = {
|
||||||
|
source = "bpg/proxmox"
|
||||||
|
version = "0.98.1"
|
||||||
|
}
|
||||||
|
local = {
|
||||||
|
source = "hashicorp/local"
|
||||||
|
version = "2.7.0"
|
||||||
|
}
|
||||||
|
random = {
|
||||||
|
source = "hashicorp/random"
|
||||||
|
version = "3.8.1"
|
||||||
|
}
|
||||||
|
tls = {
|
||||||
|
source = "hashicorp/tls"
|
||||||
|
version = "4.2.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "proxmox" {
|
||||||
|
endpoint = var.proxmox_endpoint
|
||||||
|
api_token = "${var.proxmox_token_id}=${var.proxmox_token_secret}"
|
||||||
|
insecure = true
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "local" {}
|
||||||
|
provider "random" {}
|
||||||
|
provider "tls" {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
data "proxmox_virtual_environment_version" "current" {}
|
||||||
|
output "proxmox_version" {
|
||||||
|
value = data.proxmox_virtual_environment_version.current.version
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "proxmox_virtual_environment_vm" "node1" {
|
||||||
|
vm_id = var.vm_id
|
||||||
|
name = var.vm_name
|
||||||
|
node_name = "px" # имя ноды Proxmox
|
||||||
|
on_boot = true
|
||||||
|
|
||||||
|
clone {
|
||||||
|
vm_id = var.template_id
|
||||||
|
full = true
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cloud Init ✦ пользователь, ssh-ключ, сеть
|
||||||
|
initialization {
|
||||||
|
datastore_id = var.datastore_vm
|
||||||
|
user_account {
|
||||||
|
username = var.cloudinit_user
|
||||||
|
keys = [ var.ssh_public_key ]
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_config {
|
||||||
|
ipv4 {
|
||||||
|
address = "dhcp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_device {
|
||||||
|
bridge = "vmbr1"
|
||||||
|
}
|
||||||
|
|
||||||
|
agent {
|
||||||
|
enabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output "vm_ipv4" {
|
||||||
|
value = proxmox_virtual_environment_vm.node1.ipv4_addresses
|
||||||
|
}
|
||||||
1
terraform.tfstate
Normal file
1
terraform.tfstate
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":4,"terraform_version":"1.11.5","serial":12,"lineage":"ddaa48b0-8fa2-d48c-f9c8-a548d9a46a26","outputs":{"proxmox_version":{"value":"9.1.1","type":"string"},"vm_ipv4":{"value":[["127.0.0.1"],["10.10.10.100"]],"type":["list",["list","string"]]}},"resources":[{"mode":"data","type":"proxmox_virtual_environment_version","name":"current","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"schema_version":0,"attributes":{"id":"version","release":"9.1","repository_id":"42db4a6cf33dac83","version":"9.1.1"},"sensitive_attributes":[]}]},{"mode":"managed","type":"proxmox_virtual_environment_vm","name":"node1","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"schema_version":0,"attributes":{"acpi":true,"agent":[{"enabled":true,"timeout":"15m","trim":false,"type":"virtio","wait_for_ip":[]}],"amd_sev":[],"audio_device":[],"bios":"seabios","boot_order":[],"cdrom":[],"clone":[{"datastore_id":"","full":true,"node_name":"","retries":1,"vm_id":9002}],"cpu":[],"delete_unreferenced_disks_on_destroy":true,"description":null,"disk":[],"efi_disk":[],"hook_script_file_id":null,"hostpci":[],"hotplug":null,"id":"9100","initialization":[{"datastore_id":"local","dns":[],"file_format":"qcow2","interface":"ide2","ip_config":[{"ipv4":[{"address":"dhcp","gateway":""}],"ipv6":[]}],"meta_data_file_id":"","network_data_file_id":"","type":"","user_account":[{"keys":["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc"],"password":"","username":"ubuntu"}],"user_data_file_id":"","vendor_data_file_id":""}],"ipv4_addresses":[["127.0.0.1"],["10.10.10.100"]],"ipv6_addresses":[["::1"],["fe80::be24:11ff:fe54:52f6"]],"keyboard_layout":"en-us","kvm_arguments":null,"mac_addresses":["00:00:00:00:00:00","BC:24:11:54:52:F6"],"machine":null,"memory":[],"migrate":false,"name":"ubuntu-node1","network_device":[{"bridge":"vmbr1","disconnected":false,"enabled":true,"firewall":false,"mac_address":"BC:24:11:54:52:F6","model":"virtio","mtu":0,"queues":0,"rate_limit":0,"trunks":"","vlan_id":0}],"network_interface_names":["lo","eth0"],"node_name":"px","numa":[],"on_boot":true,"operating_system":[],"pool_id":"","protection":false,"purge_on_destroy":true,"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":null,"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":[],"virtiofs":[],"vm_id":9100,"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":null}
|
||||||
1
terraform.tfstate.backup
Normal file
1
terraform.tfstate.backup
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":4,"terraform_version":"1.11.5","serial":11,"lineage":"ddaa48b0-8fa2-d48c-f9c8-a548d9a46a26","outputs":{"proxmox_version":{"value":"9.1.1","type":"string"},"vm_ipv4":{"value":[],"type":["list",["list","string"]]}},"resources":[{"mode":"data","type":"proxmox_virtual_environment_version","name":"current","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"schema_version":0,"attributes":{"id":"version","release":"9.1","repository_id":"42db4a6cf33dac83","version":"9.1.1"},"sensitive_attributes":[]}]},{"mode":"managed","type":"proxmox_virtual_environment_vm","name":"node1","provider":"provider[\"registry.opentofu.org/bpg/proxmox\"]","instances":[{"schema_version":0,"attributes":{"acpi":true,"agent":[{"enabled":true,"timeout":"15m","trim":false,"type":"virtio","wait_for_ip":[]}],"amd_sev":[],"audio_device":[],"bios":"seabios","boot_order":[],"cdrom":[],"clone":[{"datastore_id":"","full":true,"node_name":"","retries":1,"vm_id":9002}],"cpu":[],"delete_unreferenced_disks_on_destroy":true,"description":null,"disk":[],"efi_disk":[],"hook_script_file_id":null,"hostpci":[],"hotplug":null,"id":"9100","initialization":[{"datastore_id":"local","dns":[],"file_format":"qcow2","interface":"ide2","ip_config":[{"ipv4":[{"address":"dhcp","gateway":""}],"ipv6":[]}],"meta_data_file_id":"","network_data_file_id":"","type":"","user_account":[{"keys":["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc"],"password":"","username":"ubuntu"}],"user_data_file_id":"","vendor_data_file_id":""}],"ipv4_addresses":[],"ipv6_addresses":[],"keyboard_layout":"en-us","kvm_arguments":null,"mac_addresses":[],"machine":null,"memory":[],"migrate":false,"name":"ubuntu-node1","network_device":[{"bridge":"vmbr1","disconnected":false,"enabled":true,"firewall":false,"mac_address":"BC:24:11:A4:09:99","model":"virtio","mtu":0,"queues":0,"rate_limit":0,"trunks":"","vlan_id":0}],"network_interface_names":[],"node_name":"px","numa":[],"on_boot":true,"operating_system":[],"pool_id":"","protection":false,"purge_on_destroy":true,"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":null,"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":[],"virtiofs":[],"vm_id":9100,"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":null}
|
||||||
9
terraform.tfvars
Normal file
9
terraform.tfvars
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
proxmox_endpoint = "https://185.78.29.7:8006/api2/json"
|
||||||
|
proxmox_token_id = "terraform@pve!tf"
|
||||||
|
proxmox_token_secret = "API_TOKEN"
|
||||||
|
template_id = 9002
|
||||||
|
vm_id = 9100
|
||||||
|
vm_name = "ubuntu-node1"
|
||||||
|
cloudinit_user = "ubuntu"
|
||||||
|
ssh_public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPiX5bOEXfX3AvwstdAyYYHgSyGDF12NzOBCwfNPQVgo terraform@lxc"
|
||||||
|
datastore_vm = "local"
|
||||||
36
variables.tf
Normal file
36
variables.tf
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
variable "proxmox_endpoint" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "proxmox_token_id" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "proxmox_token_secret" {
|
||||||
|
type = string
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "template_id" {
|
||||||
|
type = number
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_id" {
|
||||||
|
type = number
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_name" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "cloudinit_user" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_public_key" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "datastore_vm" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user