mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 10:33:46 +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,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 == "" {
|
||||
|
Loading…
Reference in New Issue
Block a user