From c9fcb30762a46a3d6a0e48a8bb6201aa8b205dcd Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sat, 29 Mar 2025 13:04:26 -0400 Subject: [PATCH] fix(vm): prevent cloud-init username reset to `" "` during create (#1863) Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/test/resource_vm_test.go | 18 ++++++++++++++++++ proxmoxtf/resource/vm/vm.go | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/fwprovider/test/resource_vm_test.go b/fwprovider/test/resource_vm_test.go index ea6fb0bc..a2e94225 100644 --- a/fwprovider/test/resource_vm_test.go +++ b/fwprovider/test/resource_vm_test.go @@ -494,6 +494,24 @@ func TestAccResourceVMInitialization(t *testing.T) { }), ), }}}, + {"native cloud-init: username should not change", []resource.TestStep{{ + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_vm" "test_vm_cloudinit4" { + node_name = "{{.NodeName}}" + started = false + initialization { + user_account { + keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOQCHPhOV9XsJa3uq4bmKymklNy6ktgBB/+2umizgnnY"] + } + } + }`), + Check: resource.ComposeTestCheckFunc( + NoResourceAttributesSet("proxmox_virtual_environment_vm.test_vm_cloudinit4", []string{ + "initialization.0.username", + "initialization.0.password", + }), + ), + }}}, } for _, tt := range tests { diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index 4a12ec45..70da07e3 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -2937,7 +2937,9 @@ func vmGetCloudInitConfig(d *schema.ResourceData) *vms.CustomCloudInitConfig { } username := initializationUserAccountBlock[mkInitializationUserAccountUsername].(string) - initializationConfig.Username = &username + if username != "" { + initializationConfig.Username = &username + } } initializationUserDataFileID := initializationBlock[mkInitializationUserDataFileID].(string)