Skip to content

Commit

Permalink
Add protection property to the resource_vm_qemu
Browse files Browse the repository at this point in the history
  • Loading branch information
xserrat committed Apr 24, 2024
1 parent da0b8e1 commit 3c209df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/resources/vm_qemu.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ The following arguments are supported in the top level resource block.
| `bios` | `str` | `"seabios"` | The BIOS to use, options are `seabios` or `ovmf` for UEFI. |
| `onboot` | `bool` | `false` | Whether to have the VM startup after the PVE node starts. |
| `startup` | `string` | `""` | The [startup and shutdown behaviour](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#pct_startup_and_shutdown) |
| `vm_state` | `string` | `"running"` | The desired state of the VM, options are `running`, `stopped` and `started`. Do note that `started` will only start the vm on creation and won't fully manage the power state unlike `running` and `stopped` do.|
| `vm_state` | `string` | `"running"` | The desired state of the VM, options are `running`, `stopped` and `started`. Do note that `started` will only start the vm on creation and won't fully manage the power state unlike `running` and `stopped` do. |
| `oncreate` | `bool` | `true` | Whether to have the VM startup after the VM is created (deprecated, use `vm_state` instead) |
| `protection` | `bool` | `false` | Enable/disable the VM protection from being removed. The default value of `false` indicates the VM is removable. |
| `tablet` | `bool` | `true` | Enable/disable the USB tablet device. This device is usually needed to allow absolute mouse positioning with VNC. |
| `boot` | `str` | | The boot order for the VM. For example: `order=scsi0;ide2;net0`. The deprecated `legacy=` syntax is no longer supported. See the `boot` option in the [Proxmox manual](https://pve.proxmox.com/wiki/Manual:_qm.conf#_options) for more information. |
| `bootdisk` | `str` | | Enable booting from specified disk. You shouldn't need to change it under most circumstances. |
| `agent` | `int` | `0` | Set to `1` to enable the QEMU Guest Agent. Note, you must run the [`qemu-guest-agent`](https://pve.proxmox.com/wiki/Qemu-guest-agent) daemon in the guest for this to have any effect. |
| `pxe` | `bool` | `false` | If set to `true`, enable PXE boot of the VM. Also requires a `boot` order be set with Network included (eg `boot = "order=scsi0;net0"`). Note that `pxe` is mutually exclusive with `clone` modes.|
| `clone` | `str` | | The base VM from which to clone to create the new VM. Note that `clone` is mutually exclussive with `pxe` modes.|
| `pxe` | `bool` | `false` | If set to `true`, enable PXE boot of the VM. Also requires a `boot` order be set with Network included (eg `boot = "order=scsi0;net0"`). Note that `pxe` is mutually exclusive with `clone` modes. |
| `clone` | `str` | | The base VM from which to clone to create the new VM. Note that `clone` is mutually exclussive with `pxe` modes. |
| `full_clone` | `bool` | `true` | Set to `true` to create a full clone, or `false` to create a linked clone. See the [docs about cloning](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_copy_and_clone) for more info. Only applies when `clone` is set. |
| `hastate` | `str` | | Requested HA state for the resource. One of "started", "stopped", "enabled", "disabled", or "ignored". See the [docs about HA](https://pve.proxmox.com/pve-docs/chapter-ha-manager.html#ha_manager_resource_config) for more info. |
| `hagroup` | `str` | | The HA group identifier the resource belongs to (requires `hastate` to be set!). See the [docs about HA](https://pve.proxmox.com/pve-docs/chapter-ha-manager.html#ha_manager_resource_config) for more info. |
Expand Down
1 change: 1 addition & 0 deletions examples/pxe_example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ resource "proxmox_vm_qemu" "pxe-example" {
qemu_os = "l26"
scsihw = "virtio-scsi-pci"
sockets = 1
protection = false
tablet = true
target_node = "test"
vcpus = 0
Expand Down
9 changes: 9 additions & 0 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ func resourceVmQemu() *schema.Resource {
// Default: "",
Description: "Startup order of the VM",
},
"protection": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Protect VM from being removed",
},
"tablet": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -832,6 +838,7 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte
Bios: d.Get("bios").(string),
Onboot: BoolPointer(d.Get("onboot").(bool)),
Startup: d.Get("startup").(string),
Protection: BoolPointer(d.Get("protection").(bool)),
Tablet: BoolPointer(d.Get("tablet").(bool)),
Boot: d.Get("boot").(string),
BootDisk: d.Get("bootdisk").(string),
Expand Down Expand Up @@ -1108,6 +1115,7 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
Bios: d.Get("bios").(string),
Onboot: BoolPointer(d.Get("onboot").(bool)),
Startup: d.Get("startup").(string),
Protection: BoolPointer(d.Get("protection").(bool)),
Tablet: BoolPointer(d.Get("tablet").(bool)),
Boot: d.Get("boot").(string),
BootDisk: d.Get("bootdisk").(string),
Expand Down Expand Up @@ -1421,6 +1429,7 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("bios", config.Bios)
d.Set("onboot", config.Onboot)
d.Set("startup", config.Startup)
d.Set("protection", config.Protection)
d.Set("tablet", config.Tablet)
d.Set("boot", config.Boot)
d.Set("bootdisk", config.BootDisk)
Expand Down

0 comments on commit 3c209df

Please sign in to comment.