Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creation of standalone VM disks #1465

Open
vehagn opened this issue Aug 4, 2024 · 0 comments
Open

Creation of standalone VM disks #1465

vehagn opened this issue Aug 4, 2024 · 0 comments
Labels
✨ enhancement New feature or request

Comments

@vehagn
Copy link

vehagn commented Aug 4, 2024

I would like a new resource for managing "standalone" VM disks, e.g. virtual_environment_disk.

Creating a new VM disk is possible by sending a POST call to the /api2/json/nodes/{node}/storage/{storage}/content endpoint ref https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/storage/{storage}/content

I'm using the Proxmox CSI Plugin to provision Proxmox storage backed PersistentVolumes for a Kubernetes cluster. The Proxmox CSI Plugin has the possibility to automatically create VM disks in Proxmox and mount them to the correct VM, though the volumes it creates are all named vm-9999-pvc-<UUID> which makes it difficult to distinguish which Proxmox VM disk corresponds to which Kubernetes PV.

I've been able to circumvent this issue by managing VM disks using the Mastercard/restapi provider as shown below which works adequately, though I would prefer to manage it using this provider.

terraform {
  required_providers {
    restapi = {
      source  = "Mastercard/restapi"
      version = ">= 1.19.1"
    }
  }
}

variable "proxmox_api" {
  type = object({
    endpoint  = string
    insecure  = bool
    api_token = string
  })
  sensitive = true
}

variable "volume" {
  type = object({
    name = string
    node = string
    size = string
    storage = optional(string, "local-zfs")
    vmid = optional(number, 9999)
    format = optional(string, "raw")
  })
}

locals {
  filename = "vm-${var.volume.vmid}-${var.volume.name}"
}

resource "restapi_object" "proxmox-volume" {
  path = "/api2/json/nodes/${var.volume.node}/storage/${var.volume.storage}/content/"

  id_attribute = "data"

  force_new = [var.volume.size]

  data = jsonencode({
    vmid     = var.volume.vmid
    filename = local.filename
    size     = var.volume.size
    format   = var.volume.format
  })
}

An alternative solution would be changes to Proxmox CSI Plugin to allow for named VM disks, possibly related to this issue.

@vehagn vehagn added the ✨ enhancement New feature or request label Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant