add validation to vm_qemu name field (#858)

* add validation to vm_qemu name field

* changed some stuff and forgot to re-test the build. fixed now
This commit is contained in:
Bryan Heden 2023-12-06 06:23:37 -05:00 committed by GitHub
parent eca98dc58c
commit bdb1f9fdf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -21,8 +21,6 @@ Follow this [install guide](docs/guides/installation.md) to install the plugin.
* `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.
* `proxmox_vm_qemu` does not (yet) validate vm names, be sure to only use alphanumeric and dashes otherwise you may get
an opaque 400 Parameter Verification failed (indicating a bad value was sent to proxmox).
* 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.

View file

@ -73,6 +73,17 @@ func resourceVmQemu() *schema.Resource {
Optional: true,
// Default: "",
Description: "The VM name",
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
v := val.(string)
matched, err := regexp.Match("[^a-zA-Z0-9-]", []byte(v))
if err != nil {
warns = append(warns, fmt.Sprintf("%q, had an error running regexp.Match err=[%v]", key, err))
}
if matched {
errs = append(errs, fmt.Errorf("%q, must be contain only alphanumerics and hyphens", key, v))
}
return
},
},
"desc": {
Type: schema.TypeString,