Просмотр исходного кода

Merge pull request #869 from ChristianLempa/update/terraform-proxmox

update/terraform proxmox
Christian Lempa 11 месяцев назад
Родитель
Сommit
8dc65c26b4

+ 0 - 3
terraform/proxmox/credentials.auto.tfvars

@@ -1,3 +0,0 @@
-proxmox_api_url = "https://0.0.0.0:8006/api2/json"  # Your Proxmox IP Address
-proxmox_api_token_id = "terraform@pam!terraform"  # API Token ID
-proxmox_api_token_secret = "your-api-token-secret"

+ 17 - 18
terraform/proxmox/provider.tf

@@ -1,41 +1,40 @@
-# Proxmox Provider
-# ---
-# Initial Provider Configuration for Proxmox
-
 terraform {
   required_version = ">= 0.13.0"
 
   required_providers {
     proxmox = {
+      # LINK https://github.com/Telmate/terraform-provider-proxmox
       source = "telmate/proxmox"
-      version = "3.0.1-rc6"
+      version = "3.0.1-rc7"
     }
   }
 }
 
-variable "proxmox_api_url" {
+variable "PROXMOX_URL" {
   type = string
 }
 
-variable "proxmox_api_token_id" {
-  type = string
+variable "PROXMOX_USER" {
+  type      = string
+  sensitive = true
 }
 
-variable "proxmox_api_token_secret" {
-  type = string
+variable "PROXMOX_TOKEN" {
+  type      = string
+  sensitive = true
 }
 
 variable "PUBLIC_SSH_KEY" {
-  
-  # -- Public SSH Key, you want to upload to VMs and LXC containers.
-
-  type = string
+  # NOTE This is the publich SSH key, you want to upload to VMs and LXC containers.
+  type      = string
   sensitive = true
 }
 
 provider "proxmox" {
-  pm_api_url = var.proxmox_api_url
-  pm_api_token_id = var.proxmox_api_token_id
-  pm_api_token_secret = var.proxmox_api_token_secret
-  pm_tls_insecure = false  # <-- (Optional) Change to true if you are using self-signed certificates
+  pm_api_url = var.PROXMOX_URL
+  pm_api_token_id = var.PROXMOX_USER
+  pm_api_token_secret = var.PROXMOX_TOKEN
+  
+  # NOTE Optional, but recommended to set to true if you are using self-signed certificates.
+  pm_tls_insecure = false
 }

+ 102 - 0
terraform/proxmox/vm_qemu.tf

@@ -0,0 +1,102 @@
+resource "proxmox_vm_qemu" "your-vm" {
+
+  # SECTION General Settings
+
+  name = "vm-name"
+  desc = "description"
+  agent = 1  # <-- (Optional) Enable QEMU Guest Agent
+
+  # FIXME Before deployment, set the correct target node name
+  target_node = "your-proxmox-node"
+
+  # FIXME Before deployment, set the desired VM ID (must be unique on the target node)
+  vmid = "100"
+
+  # !SECTION
+  
+  # SECTION Template Settings
+
+  # FIXME Before deployment, set the correct template or VM name in the clone field
+  #       or set full_clone to false, and remote "clone" to manage existing (imported) VMs
+  clone = "your-clone-name"
+  full_clone = true
+
+  # !SECTION
+
+  # SECTION Boot Process
+
+  onboot = true 
+
+  # NOTE Change startup, shutdown and auto reboot behavior
+  startup = ""
+  automatic_reboot = false
+
+  # !SECTION
+
+  # SECTION Hardware Settings
+
+  qemu_os = "other"
+  bios = "seabios"
+  cores = 2
+  sockets = 1
+  cpu_type = "host"
+  memory = 2048
+
+  # NOTE Minimum memory of the balloon device, set to 0 to disable ballooning
+  balloon = 2048
+  
+  # !SECTION
+
+  # SECTION Network Settings
+
+  network {
+    id     = 0  # NOTE Required since 3.x.x
+    bridge = "vmbr1"
+    model  = "virtio"
+  }
+
+  # !SECTION
+
+  # SECTION Disk Settings
+  
+  # NOTE Change the SCSI controller type, since Proxmox 7.3, virtio-scsi-single is the default one         
+  scsihw = "virtio-scsi-single"
+  
+  # NOTE New disk layout (changed in 3.x.x)
+  disks {
+    ide {
+      ide0 {
+        cloudinit {
+          storage = "local-lvm"
+        }
+      }
+    }
+    virtio {
+      virtio0 {
+        disk {
+          storage = "local-lvm"
+
+          # NOTE Since 3.x.x size change disk size will trigger a disk resize
+          size = "20G"
+
+          # NOTE Enable IOThread for better disk performance in virtio-scsi-single
+          #      and enable disk replication
+          iothread = true
+          replicate = false
+        }
+      }
+    }
+  }
+
+  # !SECTION
+
+  # SECTION Cloud Init Settings
+
+  # FIXME Before deployment, adjust according to your network configuration
+  ipconfig0 = "ip=0.0.0.0/0,gw=0.0.0.0"
+  nameserver = "0.0.0.0"
+  ciuser = "your-username"
+  sshkeys = var.PUBLIC_SSH_KEY
+
+  # !SECTION
+}

+ 0 - 72
terraform/proxmox/vmqemu.tf

@@ -1,72 +0,0 @@
-resource "proxmox_vm_qemu" "your-vm" {
-  
-  # -- General settings
-
-  name = "vm-name"
-  desc = "description"
-  agent = 1  # <-- (Optional) Enable QEMU Guest Agent
-  target_node = "your-proxmox-node"  # <-- Change to the name of your Proxmox node (if you have multiple nodes)
-  tags = "your-tag-1,your-tag-2"
-  vmid = "100"
-
-  # -- Template settings
-
-  clone = "your-clone-name"  # <-- Change to the name of the template or VM you want to clone
-  full_clone = true  # <-- (Optional) Set to "false" to create a linked clone
-
-  # -- Boot Process
-
-  onboot = true 
-  startup = ""  # <-- (Optional) Change startup and shutdown behavior
-  automatic_reboot = false  # <-- Automatically reboot the VM after config change
-
-  # -- Hardware Settings
-
-  qemu_os = "other"
-  bios = "seabios"
-  cores = 2
-  sockets = 1
-  cpu_type = "host"
-  memory = 2048
-  balloon = 2048  # <-- (Optional) Minimum memory of the balloon device, set to 0 to disable ballooning
-  
-
-  # -- Network Settings
-
-  network {
-    id     = 0  # <-- ! required since 3.x.x
-    bridge = "vmbr1"
-    model  = "virtio"
-  }
-
-  # -- Disk Settings
-  
-  scsihw = "virtio-scsi-single"  # <-- (Optional) Change the SCSI controller type, since Proxmox 7.3, virtio-scsi-single is the default one         
-  
-  disks {  # <-- ! changed in 3.x.x
-    ide {
-      ide0 {
-        cloudinit {
-          storage = "local-lvm"
-        }
-      }
-    }
-    virtio {
-      virtio0 {
-        disk {
-          storage = "local-lvm"
-          size = "20G"  # <-- Change the desired disk size, ! since 3.x.x size change will trigger a disk resize
-          iothread = true  # <-- (Optional) Enable IOThread for better disk performance in virtio-scsi-single
-          replicate = false  # <-- (Optional) Enable for disk replication
-        }
-      }
-    }
-  }
-
-  # -- Cloud Init Settings
-
-  ipconfig0 = "ip=0.0.0.0/0,gw=0.0.0.0"  # <-- Change to your desired IP configuration
-  nameserver = "0.0.0.0"  # <-- Change to your desired DNS server
-  ciuser = "your-username"
-  sshkeys = var.PUBLIC_SSH_KEY  # <-- (Optional) Change to your public SSH key
-}