Skip to content

Commit 126f352

Browse files
mpywelllbajolet-hashicorp
authored andcommitted
consolidate iso device configuration
- this reroll merges iso builder's iso device and common's additional_iso_files into a single common iso struct. - disk and iso validation is now handled centrally in common - generateProxmoxDisks handles overassignment of device types with returned ui and state errors - new prestep added to clone builder to map source vm storage before packer disk and iso enumeration. Enables appending of new disks to a cloned vm.
1 parent 32afc32 commit 126f352

32 files changed

+983
-1604
lines changed

.web-docs/components/builder/clone/README.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ boot time.
271271
- `cloud_init_disk_type` (string) - The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
272272
Defaults to `ide`.
273273

274-
- `additional_iso_files` ([]additionalISOsConfig) - Additional ISO files attached to the virtual machine.
275-
See [Additional ISO Files](#additional-iso-files).
274+
- `isos` ([]ISOsConfig) - ISO files attached to the virtual machine.
275+
See [ISO Files](#iso-files).
276276

277277
- `vm_interface` (string) - Name of the network interface that Packer gets
278278
the VMs IP from. Defaults to the first non loopback interface.
@@ -498,28 +498,40 @@ Usage example (JSON):
498498
<!-- End of code generated from the comments of the cloudInitIpconfig struct in builder/proxmox/clone/config.go; -->
499499

500500

501-
### Additional ISO Files
501+
### ISO Files
502502

503-
<!-- Code generated from the comments of the additionalISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
503+
<!-- Code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
504504

505-
Additional ISO files attached to the virtual machine.
505+
One or more ISO files attached to the virtual machine.
506506

507-
Example:
507+
JSON Example:
508508

509509
```json
510-
[
511510

512-
{
513-
"device": "scsi5",
514-
"iso_file": "local:iso/virtio-win-0.1.185.iso",
515-
"unmount": true,
516-
"iso_checksum": "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
511+
"isos": [
512+
{
513+
"type": "scsi",
514+
"iso_file": "local:iso/virtio-win-0.1.185.iso",
515+
"unmount": true,
516+
"iso_checksum": "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
517+
}
518+
]
519+
520+
```
521+
HCL2 example:
522+
523+
```hcl
524+
525+
isos {
526+
type = "scsi"
527+
iso_file = "local:iso/virtio-win-0.1.185.iso"
528+
unmount = true
529+
iso_checksum = "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
517530
}
518531
519-
]
520532
```
521533

522-
<!-- End of code generated from the comments of the additionalISOsConfig struct in builder/proxmox/common/config.go; -->
534+
<!-- End of code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; -->
523535

524536

525537
<!-- Code generated from the comments of the ISOConfig struct in multistep/commonsteps/iso_config.go; DO NOT EDIT MANUALLY -->
@@ -654,20 +666,18 @@ In HCL2:
654666
<!-- End of code generated from the comments of the ISOConfig struct in multistep/commonsteps/iso_config.go; -->
655667

656668

657-
<!-- Code generated from the comments of the additionalISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
669+
<!-- Code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
658670

659-
- `device` (string) - Bus type and bus index that the ISO will be mounted on. Can be `ideX`,
660-
`sataX` or `scsiX`.
661-
For `ide` the bus index ranges from 0 to 3, for `sata` from 0 to 5 and for
662-
`scsi` from 0 to 30.
663-
Defaults to `ide3` since `ide2` is generally the boot drive.
671+
- `type` (string) - Bus type and bus index that the ISO will be mounted on. Can be `ide`,
672+
`sata` or `scsi`.
673+
Defaults to `ide`.
664674

665675
- `iso_file` (string) - Path to the ISO file to boot from, expressed as a
666676
proxmox datastore path, for example
667677
`local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso`.
668678
Either `iso_file` OR `iso_url` must be specifed.
669679

670-
- `iso_storage_pool` (string) - Proxmox storage pool onto which to upload
680+
- `storage_pool` (string) - Proxmox storage pool onto which to upload
671681
the ISO file.
672682

673683
- `iso_download_pve` (bool) - Download the ISO directly from the PVE node rather than through Packer.
@@ -679,7 +689,7 @@ In HCL2:
679689
- `keep_cdrom_device` (bool) - Keep CDRom device attached to template if unmounting ISO. Defaults to `false`.
680690
Has no effect if unmount is `false`
681691

682-
<!-- End of code generated from the comments of the additionalISOsConfig struct in builder/proxmox/common/config.go; -->
692+
<!-- End of code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; -->
683693

684694

685695
<!-- Code generated from the comments of the CDConfig struct in multistep/commonsteps/extra_iso_config.go; DO NOT EDIT MANUALLY -->

.web-docs/components/builder/iso/README.md

Lines changed: 68 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ in the image's Cloud-Init settings for provisioning.
3535

3636
### Required:
3737

38+
<!-- Code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
39+
40+
One or more ISO files attached to the virtual machine.
41+
42+
JSON Example:
43+
44+
```json
45+
46+
"isos": [
47+
{
48+
"type": "scsi",
49+
"iso_file": "local:iso/virtio-win-0.1.185.iso",
50+
"unmount": true,
51+
"iso_checksum": "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
52+
}
53+
]
54+
55+
```
56+
HCL2 example:
57+
58+
```hcl
59+
60+
isos {
61+
type = "scsi"
62+
iso_file = "local:iso/virtio-win-0.1.185.iso"
63+
unmount = true
64+
iso_checksum = "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
65+
}
66+
67+
```
68+
69+
<!-- End of code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; -->
70+
71+
3872
<!-- Code generated from the comments of the ISOConfig struct in multistep/commonsteps/iso_config.go; DO NOT EDIT MANUALLY -->
3973

4074
- `iso_checksum` (string) - The checksum for the ISO file or virtual hard drive file. The type of
@@ -64,6 +98,8 @@ in the image's Cloud-Init settings for provisioning.
6498
<!-- End of code generated from the comments of the ISOConfig struct in multistep/commonsteps/iso_config.go; -->
6599

66100

101+
See also [ISO Files](#iso-files).
102+
67103
### Optional:
68104

69105
<!-- Code generated from the comments of the Config struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
@@ -202,8 +238,8 @@ in the image's Cloud-Init settings for provisioning.
202238
- `cloud_init_disk_type` (string) - The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
203239
Defaults to `ide`.
204240

205-
- `additional_iso_files` ([]additionalISOsConfig) - Additional ISO files attached to the virtual machine.
206-
See [Additional ISO Files](#additional-iso-files).
241+
- `isos` ([]ISOsConfig) - ISO files attached to the virtual machine.
242+
See [ISO Files](#iso-files).
207243

208244
- `vm_interface` (string) - Name of the network interface that Packer gets
209245
the VMs IP from. Defaults to the first non loopback interface.
@@ -217,29 +253,6 @@ in the image's Cloud-Init settings for provisioning.
217253

218254
<!-- Code generated from the comments of the Config struct in builder/proxmox/iso/config.go; DO NOT EDIT MANUALLY -->
219255

220-
- `iso_file` (string) - Path to the ISO file to boot from, expressed as a
221-
proxmox datastore path, for example
222-
`local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso`.
223-
Either `iso_file` OR `iso_url` must be specifed.
224-
225-
- `iso_device` (string) - Bus type and bus index that the ISO will be mounted on. Can be `ideX`,
226-
`sataX` or `scsiX`.
227-
For `ide` the bus index ranges from 0 to 3, for `sata` from 0 to 5 and for
228-
`scsi` from 0 to 30.
229-
Defaults to `ide2`
230-
231-
- `iso_storage_pool` (string) - Proxmox storage pool onto which to upload
232-
the ISO file.
233-
234-
- `iso_download_pve` (bool) - Download the ISO directly from the PVE node rather than through Packer.
235-
236-
Defaults to `false`
237-
238-
- `unmount_iso` (bool) - If true, remove the mounted ISO from the template
239-
after finishing. Defaults to `false`.
240-
241-
- `keep_cdrom_device` (bool) - Keep CDRom device attached to template if unmounting ISO. Defaults to `false`.
242-
Has no effect if unmount is `false`
243256

244257
<!-- End of code generated from the comments of the Config struct in builder/proxmox/iso/config.go; -->
245258

@@ -261,28 +274,40 @@ in the image's Cloud-Init settings for provisioning.
261274
<!-- End of code generated from the comments of the ISOConfig struct in multistep/commonsteps/iso_config.go; -->
262275

263276

264-
### Additional ISO Files
277+
### ISO Files
265278

266-
<!-- Code generated from the comments of the additionalISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
279+
<!-- Code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
267280

268-
Additional ISO files attached to the virtual machine.
281+
One or more ISO files attached to the virtual machine.
269282

270-
Example:
283+
JSON Example:
271284

272285
```json
273-
[
274286

275-
{
276-
"device": "scsi5",
277-
"iso_file": "local:iso/virtio-win-0.1.185.iso",
278-
"unmount": true,
279-
"iso_checksum": "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
287+
"isos": [
288+
{
289+
"type": "scsi",
290+
"iso_file": "local:iso/virtio-win-0.1.185.iso",
291+
"unmount": true,
292+
"iso_checksum": "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
293+
}
294+
]
295+
296+
```
297+
HCL2 example:
298+
299+
```hcl
300+
301+
isos {
302+
type = "scsi"
303+
iso_file = "local:iso/virtio-win-0.1.185.iso"
304+
unmount = true
305+
iso_checksum = "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
280306
}
281307
282-
]
283308
```
284309

285-
<!-- End of code generated from the comments of the additionalISOsConfig struct in builder/proxmox/common/config.go; -->
310+
<!-- End of code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; -->
286311

287312

288313
<!-- Code generated from the comments of the ISOConfig struct in multistep/commonsteps/iso_config.go; DO NOT EDIT MANUALLY -->
@@ -417,20 +442,18 @@ In HCL2:
417442
<!-- End of code generated from the comments of the ISOConfig struct in multistep/commonsteps/iso_config.go; -->
418443

419444

420-
<!-- Code generated from the comments of the additionalISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
445+
<!-- Code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->
421446

422-
- `device` (string) - Bus type and bus index that the ISO will be mounted on. Can be `ideX`,
423-
`sataX` or `scsiX`.
424-
For `ide` the bus index ranges from 0 to 3, for `sata` from 0 to 5 and for
425-
`scsi` from 0 to 30.
426-
Defaults to `ide3` since `ide2` is generally the boot drive.
447+
- `type` (string) - Bus type and bus index that the ISO will be mounted on. Can be `ide`,
448+
`sata` or `scsi`.
449+
Defaults to `ide`.
427450

428451
- `iso_file` (string) - Path to the ISO file to boot from, expressed as a
429452
proxmox datastore path, for example
430453
`local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso`.
431454
Either `iso_file` OR `iso_url` must be specifed.
432455

433-
- `iso_storage_pool` (string) - Proxmox storage pool onto which to upload
456+
- `storage_pool` (string) - Proxmox storage pool onto which to upload
434457
the ISO file.
435458

436459
- `iso_download_pve` (bool) - Download the ISO directly from the PVE node rather than through Packer.
@@ -442,7 +465,7 @@ In HCL2:
442465
- `keep_cdrom_device` (bool) - Keep CDRom device attached to template if unmounting ISO. Defaults to `false`.
443466
Has no effect if unmount is `false`
444467

445-
<!-- End of code generated from the comments of the additionalISOsConfig struct in builder/proxmox/common/config.go; -->
468+
<!-- End of code generated from the comments of the ISOsConfig struct in builder/proxmox/common/config.go; -->
446469

447470

448471
<!-- Code generated from the comments of the CDConfig struct in multistep/commonsteps/extra_iso_config.go; DO NOT EDIT MANUALLY -->

builder/proxmox/clone/builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
3939
Debug: b.config.PackerDebug,
4040
DebugKeyPath: fmt.Sprintf("%s.pem", b.config.PackerBuildName),
4141
},
42+
&StepMapSourceDisks{},
4243
}
4344
postSteps := []multistep.Step{}
4445

builder/proxmox/clone/config.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"fmt"
1212
"net"
1313
"net/netip"
14-
"regexp"
1514
"strings"
1615

1716
proxmoxcommon "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
@@ -130,53 +129,6 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, []string, error) {
130129
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("%d ipconfig blocks given, but only %d network interfaces defined", len(c.Ipconfigs), len(c.NICs)))
131130
}
132131

133-
// each device type has a maximum number of devices that can be attached.
134-
// count disks, additional isos configured for each device type, error if too many.
135-
ideCount := 0
136-
sataCount := 0
137-
scsiCount := 0
138-
virtIOCount := 0
139-
// count disks
140-
for _, disks := range c.Disks {
141-
switch disks.Type {
142-
case "ide":
143-
ideCount++
144-
case "sata":
145-
sataCount++
146-
case "scsi":
147-
scsiCount++
148-
case "virtio":
149-
virtIOCount++
150-
}
151-
}
152-
// count additional_iso_files devices
153-
for _, iso := range c.AdditionalISOFiles {
154-
// get device type from iso.Device
155-
rd := regexp.MustCompile(`\D+`)
156-
device := rd.FindString(iso.Device)
157-
switch device {
158-
case "ide":
159-
ideCount++
160-
case "sata":
161-
sataCount++
162-
case "scsi":
163-
scsiCount++
164-
}
165-
}
166-
// validate device type allocations
167-
if ideCount > 4 {
168-
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("maximum 4 IDE disks and ISOs supported"))
169-
}
170-
if sataCount > 6 {
171-
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("maximum 6 SATA disks and ISOs supported"))
172-
}
173-
if scsiCount > 31 {
174-
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("maximum 31 SCSI disks and ISOs supported"))
175-
}
176-
if virtIOCount > 16 {
177-
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("maximum 16 VirtIO disks supported"))
178-
}
179-
180132
if errs != nil && len(errs.Errors) > 0 {
181133
return nil, warnings, errs
182134
}

0 commit comments

Comments
 (0)