mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 19:12:59 +00:00
fix(vm): improve error handling when updating initialization
block (#1858)
* fix(vm): improve error handling when updating `initialization` block Fix for an edge case where a VM is created without an initialization block, then any subsequent update to the block would cause a panic. Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> * linter Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
2da4e3de1c
commit
539b902633
@ -5168,15 +5168,19 @@ 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))
|
tflog.Debug(ctx, fmt.Sprintf("CloudInit must be moved from %s to %s", existingInterface, initializationInterface))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mustChangeDatastore := false
|
||||||
|
|
||||||
oldInit, _ := d.GetChange(mkInitialization)
|
oldInit, _ := d.GetChange(mkInitialization)
|
||||||
|
if len(oldInit.([]interface{})) > 0 {
|
||||||
oldInitBlock := oldInit.([]interface{})[0].(map[string]interface{})
|
oldInitBlock := oldInit.([]interface{})[0].(map[string]interface{})
|
||||||
prevDatastoreID := oldInitBlock[mkInitializationDatastoreID].(string)
|
prevDatastoreID := oldInitBlock[mkInitializationDatastoreID].(string)
|
||||||
|
|
||||||
mustChangeDatastore := prevDatastoreID != initializationDatastoreID
|
mustChangeDatastore = prevDatastoreID != initializationDatastoreID
|
||||||
if mustChangeDatastore {
|
if mustChangeDatastore {
|
||||||
tflog.Debug(ctx, fmt.Sprintf("CloudInit must be moved from datastore %s to datastore %s",
|
tflog.Debug(ctx, fmt.Sprintf("CloudInit must be moved from datastore %s to datastore %s",
|
||||||
prevDatastoreID, initializationDatastoreID))
|
prevDatastoreID, initializationDatastoreID))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if mustMove || mustChangeDatastore || existingInterface == "" {
|
if mustMove || mustChangeDatastore || existingInterface == "" {
|
||||||
// CloudInit must be moved, either from a device to another or from a datastore
|
// CloudInit must be moved, either from a device to another or from a datastore
|
||||||
|
Loading…
Reference in New Issue
Block a user