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

[3.0.1-rc1] Remove ISO setting and unlock ide2 #937

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions docs/resources/vm_qemu.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ infrastructure to support the Network PXE boot request by the VM.
resource "proxmox_vm_qemu" "resource-name" {
name = "VM-name"
target_node = "Node to create the VM on"
iso = "ISO file name"

disks {
ide {
ide2 {
cdrom {
iso = "ISO file"
}
}
}
}

### or for a Clone VM operation
# clone = "template to clone"
Expand Down Expand Up @@ -49,7 +58,7 @@ Specifying the `pxe = true` option will enable the Virtual Machine to perform a
In addition to enabling the PXE mode, a few other options should be specified to ensure successful
boot of the VM. A minimal Resource stanza for a PXE boot VM might look like this:

```
```hcl
resource "proxmox_vm_qemu" "pxe-minimal-example" {
name = "pxe-minimal-example"
agent = 0
Expand Down Expand Up @@ -95,9 +104,8 @@ The following arguments are supported in the top level resource block.
| `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. |
| `iso` | `str` | | The name of the ISO image to mount to the VM in the format: [storage pool]:iso/[name of iso file]. Only applies when `clone` is not set. Either `clone` or `iso` needs to be set. Note that `iso` is mutually exclussive with `clone` and `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 `iso` and `clone` modes. |
| `clone` | `str` | | The base VM from which to clone to create the new VM. Note that `clone` is mutually exclussive with `pxe` and `iso` 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 Expand Up @@ -195,7 +203,7 @@ resource "proxmox_vm_qemu" "resource-name" {

### Disks.Ide Block

The `disks.ide` block is used to configure disks of type ide. It may only be specified once. It has the options `ide0` through `ide1`. Each disk can have only one of the following mutually exclusive sub types `cdrom`, `disk`, `passthrough`. Configuration for these sub types can be found in their respective chapters:
The `disks.ide` block is used to configure disks of type ide. It may only be specified once. It has the options `ide0` through `ide2`. Each disk can have only one of the following mutually exclusive sub types `cdrom`, `disk`, `passthrough`. Configuration for these sub types can be found in their respective chapters:

* `cdrom`: [Disks.x.Cdrom Block](#disksxcdrom-block).
* `disk`: [Disks.x.Disk Block](#disksxdisk-block).
Expand All @@ -212,7 +220,7 @@ resource "proxmox_vm_qemu" "resource-name" {
//<arguments omitted for brevity...>
}
}
ide1 {
ide2 {
passthrough {
//<arguments omitted for brevity...>
}
Expand Down
49 changes: 12 additions & 37 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,11 @@ func resourceVmQemu() *schema.Resource {
ForceNew: true,
ConflictsWith: []string{"clone"},
},
"iso": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"clone"},
},
"clone": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"iso", "pxe"},
ConflictsWith: []string{"pxe"},
},
"cloudinit_cdrom_storage": {
Type: schema.TypeString,
Expand Down Expand Up @@ -462,7 +456,7 @@ func resourceVmQemu() *schema.Resource {
Schema: map[string]*schema.Schema{
"ide0": schema_Ide("ide0"),
"ide1": schema_Ide("ide1"),
// ide2 reserved for cdrom
"ide2": schema_Ide("ide2"),
// ide3 reserved for cloudinit
},
},
Expand Down Expand Up @@ -871,7 +865,6 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte
}

config.Disks = mapToStruct_QemuStorages(d)
setIso(d, &config)
setCloudInitDisk(d, &config)

if len(qemuVgaList) > 0 {
Expand Down Expand Up @@ -933,7 +926,7 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte

vmr.SetPool(d.Get("pool").(string))

// check if ISO, clone, or PXE boot
// check if clone, or PXE boot
if d.Get("clone").(string) != "" {
fullClone := 1
if !d.Get("full_clone").(bool) {
Expand Down Expand Up @@ -971,13 +964,6 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte
return diag.FromErr(err)
}

} else if d.Get("iso").(string) != "" {
config.QemuIso = d.Get("iso").(string)
log.Print("[DEBUG][QemuVmCreate] create with ISO")
err := config.Create(vmr, client)
if err != nil {
return diag.FromErr(err)
}
} else if d.Get("pxe").(bool) {
var found bool
bs := d.Get("boot").(string)
Expand Down Expand Up @@ -1006,7 +992,11 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte
return diag.FromErr(err)
}
} else {
return diag.FromErr(fmt.Errorf("either 'clone', 'iso', or 'pxe' must be set"))
log.Print("[DEBUG][QemuVmCreate] create with ISO")
err := config.Create(vmr, client)
if err != nil {
return diag.FromErr(err)
}
}
} else {
log.Printf("[DEBUG][QemuVmCreate] recycling VM vmId: %d", vmr.VmId())
Expand Down Expand Up @@ -1163,7 +1153,6 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
}

config.Disks = mapToStruct_QemuStorages(d)
setIso(d, &config)
setCloudInitDisk(d, &config)

logger.Debug().Int("vmid", vmID).Msgf("Updating VM with the following configuration: %+v", config)
Expand Down Expand Up @@ -1464,7 +1453,6 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("smbios", ReadSmbiosArgs(config.Smbios1))
d.Set("linked_vmid", config.LinkedVmId)
d.Set("disks", mapFromStruct_ConfigQemu(config.Disks))
d.Set("iso", getIso(config.Disks))
d.Set("cloudinit_cdrom_storage", getCloudInitDisk(config.Disks))

// Some dirty hacks to populate undefined keys with default values.
Expand Down Expand Up @@ -2000,29 +1988,13 @@ func setCloudInitDisk(d *schema.ResourceData, config *pxapi.ConfigQemu) {
}
}

func setIso(d *schema.ResourceData, config *pxapi.ConfigQemu) {
iso := d.Get("iso").(string)
if iso == "" {
config.Disks.Ide.Disk_2 = &pxapi.QemuIdeStorage{CdRom: &pxapi.QemuCdRom{}}
return
}
config.Disks.Ide.Disk_2 = &pxapi.QemuIdeStorage{CdRom: &pxapi.QemuCdRom{Iso: mapToStruct_IsoFile(iso)}}
}

func getCloudInitDisk(config *pxapi.QemuStorages) string {
if config != nil && config.Ide != nil && config.Ide.Disk_3 != nil && config.Ide.Disk_3.CloudInit != nil {
return config.Ide.Disk_3.CloudInit.Storage
}
return ""
}

func getIso(config *pxapi.QemuStorages) string {
if config != nil && config.Ide != nil && config.Ide.Disk_2 != nil && config.Ide.Disk_2.CdRom != nil {
return mapFormStruct_IsoFile(config.Ide.Disk_2.CdRom.Iso)
}
return ""
}

// Map struct to the terraform schema
func mapFromStruct_ConfigQemu(config *pxapi.QemuStorages) []interface{} {
if config == nil {
Expand Down Expand Up @@ -2094,13 +2066,15 @@ func mapFromStruct_QemuIdeDisks(config *pxapi.QemuIdeDisks) []interface{} {
}
ide_0 := mapFromStruct_QemuIdeStorage(config.Disk_0, "ide0")
ide_1 := mapFromStruct_QemuIdeStorage(config.Disk_1, "ide1")
if ide_0 == nil && ide_1 == nil {
ide_2 := mapFromStruct_QemuIdeStorage(config.Disk_2, "ide2")
if ide_0 == nil && ide_1 == nil && ide_2 == nil {
return nil
}
return []interface{}{
map[string]interface{}{
"ide0": ide_0,
"ide1": ide_1,
"ide2": ide_2,
},
}
}
Expand Down Expand Up @@ -2453,6 +2427,7 @@ func mapToStruct_QemuIdeDisks(ide *pxapi.QemuIdeDisks, schema map[string]interfa
disks := schemaItem[0].(map[string]interface{})
mapToStruct_QemuIdeStorage(ide.Disk_0, "ide0", disks)
mapToStruct_QemuIdeStorage(ide.Disk_1, "ide1", disks)
mapToStruct_QemuIdeStorage(ide.Disk_2, "ide2", disks)
}

func mapToStruct_QemuIdeStorage(ide *pxapi.QemuIdeStorage, key string, schema map[string]interface{}) {
Expand Down
Loading