Skip to content
Open
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
3 changes: 3 additions & 0 deletions .web-docs/components/builder/clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ boot time.
- `cloud_init_disk_type` (string) - The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
Defaults to `ide`.

- `cloud_init_disable_upgrade_packages` (bool) - Disable Upgrade Packages behaviour for Cloud-Init.
Defaults to `false`.

- `additional_iso_files` ([]ISOsConfig) - ISO files attached to the virtual machine.
See [ISOs](#isos).

Expand Down
3 changes: 3 additions & 0 deletions .web-docs/components/builder/iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ in the image's Cloud-Init settings for provisioning.
- `cloud_init_disk_type` (string) - The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
Defaults to `ide`.

- `cloud_init_disable_upgrade_packages` (bool) - Disable Upgrade Packages behaviour for Cloud-Init.
Defaults to `false`.

- `additional_iso_files` ([]ISOsConfig) - ISO files attached to the virtual machine.
See [ISOs](#isos).

Expand Down
462 changes: 232 additions & 230 deletions builder/proxmox/clone/config.hcl2spec.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions builder/proxmox/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ type Config struct {
// The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
// Defaults to `ide`.
CloudInitDiskType string `mapstructure:"cloud_init_disk_type"`
// Disable Upgrade Packages behaviour for Cloud-Init.
// Defaults to `false`.
CloudInitDisableUpgradePackages bool `mapstructure:"cloud_init_disable_upgrade_packages"`

// ISO files attached to the virtual machine.
// See [ISOs](#isos).
Expand Down
438 changes: 220 additions & 218 deletions builder/proxmox/common/config.hcl2spec.go

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion builder/proxmox/common/step_finalize_template_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type stepFinalizeTemplateConfig struct{}
type templateFinalizer interface {
GetVmConfig(*proxmox.VmRef) (map[string]interface{}, error)
SetVmConfig(*proxmox.VmRef, map[string]interface{}) (interface{}, error)
Version() (proxmox.Version, error)
}

var _ templateFinalizer = &proxmox.Client{}
Expand All @@ -32,6 +33,14 @@ func (s *stepFinalizeTemplateConfig) Run(ctx context.Context, state multistep.St
c := state.Get("config").(*Config)
vmRef := state.Get("vmRef").(*proxmox.VmRef)

proxmoxVersion, err := client.Version()
if err != nil {
err := fmt.Errorf("error fetching backend version: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

changes := make(map[string]interface{})

changes["name"] = c.VMName
Expand Down Expand Up @@ -87,11 +96,25 @@ func (s *stepFinalizeTemplateConfig) Run(ctx context.Context, state multistep.St
if vmParams[controller] == nil {
ui.Say("Adding a cloud-init cdrom in storage pool " + cloudInitStoragePool)
changes[controller] = cloudInitStoragePool + ":cloudinit"
// Cloud-Init `Upgrade Packages` not available in versions lower than 8
if proxmoxVersion.Major >= 8 {
switch c.CloudInitDisableUpgradePackages {
case true:
changes["ciupgrade"] = false
case false:
changes["ciupgrade"] = true
}
} else {
// only write to UI if the cloud_init_disable_upgrade_packages is configured but the backend is an incompatible version
if c.CloudInitDisableUpgradePackages {
ui.Say("cloud_init_disable_upgrade_packages is set to true, but not supported in Proxmox versions lower than 8. No changes made.")
}
}
cloudInitAttached = true
break
}
}
if cloudInitAttached == false {
if !cloudInitAttached {
err := fmt.Errorf("Found no free controller of type %s for a cloud-init cdrom", c.CloudInitDiskType)
state.Put("error", err)
ui.Error(err.Error())
Expand Down
55 changes: 51 additions & 4 deletions builder/proxmox/common/step_finalize_template_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type finalizerMock struct {
getConfig func() (map[string]interface{}, error)
setConfig func(map[string]interface{}) (string, error)
version func() (proxmox.Version, error)
}

func (m finalizerMock) GetVmConfig(*proxmox.VmRef) (map[string]interface{}, error) {
Expand All @@ -26,6 +27,9 @@ func (m finalizerMock) GetVmConfig(*proxmox.VmRef) (map[string]interface{}, erro
func (m finalizerMock) SetVmConfig(vmref *proxmox.VmRef, c map[string]interface{}) (interface{}, error) {
return m.setConfig(c)
}
func (m finalizerMock) Version() (proxmox.Version, error) {
return m.version()
}

var _ templateFinalizer = finalizerMock{}

Expand All @@ -40,6 +44,7 @@ func TestTemplateFinalize(t *testing.T) {
setConfigErr error
expectedAction multistep.StepAction
expectedDelete []string
proxmoxVersion uint8
}{
{
name: "empty config changes name and description",
Expand Down Expand Up @@ -106,10 +111,36 @@ func TestTemplateFinalize(t *testing.T) {
{
name: "all options with cloud-init",
builderConfig: &Config{
TemplateName: "my-template",
TemplateDescription: "some-description",
CloudInit: true,
CloudInitDiskType: "ide",
TemplateName: "my-template",
TemplateDescription: "some-description",
CloudInit: true,
CloudInitDiskType: "ide",
CloudInitDisableUpgradePackages: true,
},
initialVMConfig: map[string]interface{}{
"name": "dummy",
"description": "Packer ephemeral build VM",
"bootdisk": "virtio0",
"virtio0": "ceph01:base-223-disk-0,cache=unsafe,media=disk,size=32G",
"ciupgrade": true,
},
expectCallSetConfig: true,
expectedVMConfig: map[string]interface{}{
"name": "my-template",
"description": "some-description",
"ide0": "ceph01:cloudinit",
"ciupgrade": false,
},
expectedAction: multistep.ActionContinue,
},
{
name: "cloud-init ignore disable upgrade packages for proxmox backends below version 8.x",
builderConfig: &Config{
TemplateName: "my-template",
TemplateDescription: "some-description",
CloudInit: true,
CloudInitDiskType: "ide",
CloudInitDisableUpgradePackages: true,
},
initialVMConfig: map[string]interface{}{
"name": "dummy",
Expand All @@ -124,6 +155,7 @@ func TestTemplateFinalize(t *testing.T) {
"ide0": "ceph01:cloudinit",
},
expectedAction: multistep.ActionContinue,
proxmoxVersion: 7,
},
{
name: "no available controller for cloud-init drive",
Expand Down Expand Up @@ -210,6 +242,21 @@ func TestTemplateFinalize(t *testing.T) {

return "", c.setConfigErr
},
version: func() (proxmox.Version, error) {
if c.proxmoxVersion != 0 {
return proxmox.Version{
Major: c.proxmoxVersion,
Minor: 0,
Patch: 0,
}, nil
} else {
return proxmox.Version{
Major: 8,
Minor: 0,
Patch: 0,
}, nil
}
},
}

state := new(multistep.BasicStateBag)
Expand Down
Loading