diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index 7a5a2440..4a12ec45 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -5168,14 +5168,18 @@ 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)) } - oldInit, _ := d.GetChange(mkInitialization) - oldInitBlock := oldInit.([]interface{})[0].(map[string]interface{}) - prevDatastoreID := oldInitBlock[mkInitializationDatastoreID].(string) + mustChangeDatastore := false - mustChangeDatastore := prevDatastoreID != initializationDatastoreID - if mustChangeDatastore { - tflog.Debug(ctx, fmt.Sprintf("CloudInit must be moved from datastore %s to datastore %s", - prevDatastoreID, initializationDatastoreID)) + oldInit, _ := d.GetChange(mkInitialization) + if len(oldInit.([]interface{})) > 0 { + oldInitBlock := oldInit.([]interface{})[0].(map[string]interface{}) + prevDatastoreID := oldInitBlock[mkInitializationDatastoreID].(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 == "" {