Skip to content

Commit

Permalink
add validation to vm_qemu name field (#858)
Browse files Browse the repository at this point in the history
* add validation to vm_qemu name field

* changed some stuff and forgot to re-test the build. fixed now
  • Loading branch information
hedenface authored Dec 6, 2023
1 parent eca98dc commit bdb1f9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 11 additions & 0 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bdb1f9f

Please sign in to comment.