From 73c1294979b956939b755ac05796fb1a68f92f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 21 Aug 2023 01:53:10 +0200 Subject: [PATCH] fix(vm): fix CloudInit datastore change support (#509) The datastore update support introduced in #486 only worked if the CloudInit interface was also changed at the same time. This commit fixes the problem. Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmoxtf/resource/vm.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/proxmoxtf/resource/vm.go b/proxmoxtf/resource/vm.go index 428e80a3..4ae83900 100644 --- a/proxmoxtf/resource/vm.go +++ b/proxmoxtf/resource/vm.go @@ -5270,7 +5270,17 @@ func vmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D tflog.Debug(ctx, fmt.Sprintf("CloudInit must be moved from %s to %s", existingInterface, initializationInterface)) } - if mustMove || d.HasChange(mkResourceVirtualEnvironmentVMInitializationDatastoreID) || existingInterface == "" { + oldInit, _ := d.GetChange(mkResourceVirtualEnvironmentVMInitialization) + oldInitBlock := oldInit.([]interface{})[0].(map[string]interface{}) + prevDatastoreID := oldInitBlock[mkResourceVirtualEnvironmentVMInitializationDatastoreID].(string) + + mustChangeDatastore := prevDatastoreID != initializationDatastoreID + if mustChangeDatastore { + tflog.Debug(ctx, fmt.Sprintf("CloudInit must be moved from datastore %s to datastore %s", + prevDatastoreID, initializationDatastoreID)) + } + + if mustMove || mustChangeDatastore || existingInterface == "" { // CloudInit must be moved, either from a device to another or from a datastore // to another (or both). This requires the VM to be stopped. if err := vmShutdown(ctx, vmAPI, d); err != nil {