From 7ae7033ee0c09d7774f5211cc46faaf5ea8b4136 Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Thu, 12 Sep 2024 14:07:28 +0800 Subject: [PATCH 1/3] fix: do not expose empty cipassword to API Fixes https://github.com/Telmate/terraform-provider-proxmox/issues/1097 --- proxmox/config_qemu_cloudinit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxmox/config_qemu_cloudinit.go b/proxmox/config_qemu_cloudinit.go index aaf1b7ee..13c2dc92 100644 --- a/proxmox/config_qemu_cloudinit.go +++ b/proxmox/config_qemu_cloudinit.go @@ -128,7 +128,7 @@ func (config CloudInit) mapToAPI(current *CloudInit, params map[string]interface if config.UpgradePackages != nil && !version.Smaller(Version{Major: 8}) { params["ciupgrade"] = Btoi(*config.UpgradePackages) } - if config.UserPassword != nil { + if config.UserPassword != nil && *config.UserPassword != "" { params["cipassword"] = *config.UserPassword } return From 1962aadae414c4f1098c0b1c8c06427d1ad52b73 Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Mon, 30 Sep 2024 13:58:47 +0800 Subject: [PATCH 2/3] fix: delete cipassword when updated to empty value --- proxmox/config_qemu_cloudinit.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proxmox/config_qemu_cloudinit.go b/proxmox/config_qemu_cloudinit.go index 13c2dc92..a49b4868 100644 --- a/proxmox/config_qemu_cloudinit.go +++ b/proxmox/config_qemu_cloudinit.go @@ -72,6 +72,9 @@ func (config CloudInit) mapToAPI(current *CloudInit, params map[string]interface delete += ",ciuser" } } + if config.UserPassword != nil && *config.UserPassword == "" { + delete += ",cipassword" + } if config.DNS != nil { if config.DNS.SearchDomain != nil { if *config.DNS.SearchDomain != "" { From 3df2b32281278d7c516802b7669f92a67dd0cf26 Mon Sep 17 00:00:00 2001 From: Yury Bushmelev Date: Mon, 30 Sep 2024 13:59:26 +0800 Subject: [PATCH 3/3] test: add cipassword-related unit tests --- proxmox/config_qemu_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/proxmox/config_qemu_test.go b/proxmox/config_qemu_test.go index e0b264c9..6fd0c554 100644 --- a/proxmox/config_qemu_test.go +++ b/proxmox/config_qemu_test.go @@ -593,6 +593,9 @@ func Test_ConfigQemu_mapToAPI(t *testing.T) { output: map[string]interface{}{}}, {name: `CloudInit Username empty`, config: &ConfigQemu{CloudInit: &CloudInit{Username: util.Pointer("")}}, + output: map[string]interface{}{}}, + {name: `CloudInit UserPassword empty`, + config: &ConfigQemu{CloudInit: &CloudInit{UserPassword: util.Pointer("")}}, output: map[string]interface{}{}}}, update: []test{ {name: `CloudInit Custom clear`, @@ -863,7 +866,11 @@ func Test_ConfigQemu_mapToAPI(t *testing.T) { {name: `CloudInit Username empty`, config: &ConfigQemu{CloudInit: &CloudInit{Username: util.Pointer("")}}, currentConfig: ConfigQemu{CloudInit: &CloudInit{Username: util.Pointer("admin")}}, - output: map[string]interface{}{"delete": "ciuser"}}}}, + output: map[string]interface{}{"delete": "ciuser"}}, + {name: `CloudInit UserPassword empty`, + config: &ConfigQemu{CloudInit: &CloudInit{UserPassword: util.Pointer("")}}, + currentConfig: ConfigQemu{CloudInit: &CloudInit{UserPassword: util.Pointer("Abc123!")}}, + output: map[string]interface{}{"delete": "cipassword"}}}}, {category: `Description`, create: []test{ {name: `Description empty`,