Restructure: move infra packages to root level
This commit is contained in:
90
terraform-pve-vm/terraform/main.tf
Normal file
90
terraform-pve-vm/terraform/main.tf
Normal file
@@ -0,0 +1,90 @@
|
||||
locals {
|
||||
# VM definitions: name, node, vmid, static IP
|
||||
vms = {
|
||||
for idx, suffix in var.name_suffixes : "vm-${suffix}" => {
|
||||
name = "${var.name_prefix}-${suffix}"
|
||||
node = element(["mk33", "mk34", "mk39"], idx)
|
||||
vmid = var.vmid_base + idx
|
||||
ipv4 = "${var.subnet_prefix}.30.${var.vmid_base + idx}/18"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "proxmox_virtual_environment_vm" "ubuntu_vm" {
|
||||
for_each = local.vms
|
||||
|
||||
name = each.value.name
|
||||
node_name = each.value.node
|
||||
vm_id = each.value.vmid
|
||||
|
||||
tags = concat(var.tags, [each.key])
|
||||
|
||||
# ── CPU / Memory ──────────────────────────
|
||||
cpu {
|
||||
cores = var.cores
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = var.memory
|
||||
}
|
||||
|
||||
# ── QEMU Guest Agent ──────────────────────
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
# ── Boot / EFI ────────────────────────────
|
||||
bios = "ovmf"
|
||||
|
||||
efi_disk {
|
||||
datastore_id = var.storage
|
||||
type = "4m"
|
||||
}
|
||||
|
||||
machine = "q35"
|
||||
|
||||
# ── SCSI Controller ───────────────────────
|
||||
scsi_hardware = "virtio-scsi-single"
|
||||
|
||||
# ── Disk (Cloud-init image) ───────────────
|
||||
disk {
|
||||
datastore_id = var.storage
|
||||
file_id = var.cloud_image_id
|
||||
interface = "scsi0"
|
||||
iothread = true
|
||||
discard = "on"
|
||||
size = var.disk_size
|
||||
}
|
||||
|
||||
# ── Network ─────────────────────────────────
|
||||
network_device {
|
||||
bridge = var.bridge
|
||||
}
|
||||
|
||||
# ── VGA / Console ─────────────────────────
|
||||
vga {
|
||||
type = "std"
|
||||
}
|
||||
|
||||
# ── Cloud-Init ─────────────────────────────
|
||||
initialization {
|
||||
datastore_id = var.cloudinit_storage
|
||||
|
||||
user_account {
|
||||
username = "jarvis"
|
||||
password = "ubuntu"
|
||||
keys = [file(var.ssh_key_path)]
|
||||
}
|
||||
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = each.value.ipv4
|
||||
gateway = var.gateway
|
||||
}
|
||||
}
|
||||
|
||||
dns {
|
||||
servers = var.dns_servers
|
||||
}
|
||||
}
|
||||
}
|
||||
19
terraform-pve-vm/terraform/outputs.tf
Normal file
19
terraform-pve-vm/terraform/outputs.tf
Normal file
@@ -0,0 +1,19 @@
|
||||
output "vm_names" {
|
||||
description = "Created VM names"
|
||||
value = [for vm in proxmox_virtual_environment_vm.ubuntu_vm : vm.name]
|
||||
}
|
||||
|
||||
output "vm_ids" {
|
||||
description = "Created VM IDs"
|
||||
value = [for vm in proxmox_virtual_environment_vm.ubuntu_vm : vm.vm_id]
|
||||
}
|
||||
|
||||
output "vm_nodes" {
|
||||
description = "PVE nodes hosting each VM"
|
||||
value = { for k, vm in proxmox_virtual_environment_vm.ubuntu_vm : k => vm.node_name }
|
||||
}
|
||||
|
||||
output "vm_ipv4" {
|
||||
description = "Static IPv4 addresses"
|
||||
value = { for k, vm in proxmox_virtual_environment_vm.ubuntu_vm : k => vm.initialization[0].ip_config[0].ipv4[0].address }
|
||||
}
|
||||
14
terraform-pve-vm/terraform/providers.tf
Normal file
14
terraform-pve-vm/terraform/providers.tf
Normal file
@@ -0,0 +1,14 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "bpg/proxmox"
|
||||
version = "0.70.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "proxmox" {
|
||||
endpoint = var.pm_api_url
|
||||
api_token = "${var.pm_api_token_id}=${var.pm_api_token_secret}"
|
||||
insecure = true
|
||||
}
|
||||
119
terraform-pve-vm/terraform/variables.tf
Normal file
119
terraform-pve-vm/terraform/variables.tf
Normal file
@@ -0,0 +1,119 @@
|
||||
variable "pm_api_url" {
|
||||
description = "Proxmox API URL"
|
||||
type = string
|
||||
default = "https://192.168.7.33:8006/api2/json"
|
||||
}
|
||||
|
||||
variable "pm_api_token_id" {
|
||||
description = "Proxmox API token ID"
|
||||
type = string
|
||||
default = "root@pam!terraform"
|
||||
}
|
||||
|
||||
variable "pm_api_token_secret" {
|
||||
description = "Proxmox API token secret"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "node" {
|
||||
description = "Target PVE node"
|
||||
type = string
|
||||
default = "mk33"
|
||||
}
|
||||
|
||||
variable "vmid_base" {
|
||||
description = "Starting VMID for the first VM"
|
||||
type = number
|
||||
default = 3034
|
||||
}
|
||||
|
||||
variable "vm_count" {
|
||||
description = "Number of VMs to create"
|
||||
type = number
|
||||
default = 3
|
||||
}
|
||||
|
||||
variable "name_prefix" {
|
||||
description = "Hostname prefix for VMs"
|
||||
type = string
|
||||
default = "vm"
|
||||
}
|
||||
|
||||
variable "name_suffixes" {
|
||||
description = "Per-VM name suffixes (artemis, jarvis, friday)"
|
||||
type = list(string)
|
||||
default = ["artemis", "jarvis", "friday"]
|
||||
}
|
||||
|
||||
variable "subnet_prefix" {
|
||||
description = "First two octets of IPv4"
|
||||
type = string
|
||||
default = "192.168"
|
||||
}
|
||||
|
||||
variable "cores" {
|
||||
description = "CPU cores per VM"
|
||||
type = number
|
||||
default = 2
|
||||
}
|
||||
|
||||
variable "memory" {
|
||||
description = "RAM in MB per VM"
|
||||
type = number
|
||||
default = 4096
|
||||
}
|
||||
|
||||
variable "disk_size" {
|
||||
description = "Disk size in GB"
|
||||
type = number
|
||||
default = 64
|
||||
}
|
||||
|
||||
variable "storage" {
|
||||
description = "Storage pool for VM disk"
|
||||
type = string
|
||||
default = "local"
|
||||
}
|
||||
|
||||
variable "bridge" {
|
||||
description = "Network bridge"
|
||||
type = string
|
||||
default = "vmbr0"
|
||||
}
|
||||
|
||||
variable "gateway" {
|
||||
description = "IPv4 gateway"
|
||||
type = string
|
||||
default = "192.168.18.1"
|
||||
}
|
||||
|
||||
variable "dns_servers" {
|
||||
description = "DNS servers"
|
||||
type = list(string)
|
||||
default = ["192.168.7.7", "1.1.1.1"]
|
||||
}
|
||||
|
||||
variable "ssh_key_path" {
|
||||
description = "Path to SSH public key for jarvis user"
|
||||
type = string
|
||||
default = "artemis_key.pub"
|
||||
}
|
||||
|
||||
variable "cloud_image_id" {
|
||||
description = "Cloud-init image file ID on storage (storage:path)"
|
||||
type = string
|
||||
default = "local:iso/noble-server-cloudimg-amd64.img"
|
||||
}
|
||||
|
||||
variable "cloudinit_storage" {
|
||||
description = "Storage pool for cloud-init drive"
|
||||
type = string
|
||||
default = "local"
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Base tags for all VMs"
|
||||
type = list(string)
|
||||
default = ["terraform", "cloudinit-vm"]
|
||||
}
|
||||
Reference in New Issue
Block a user