Skip to content

Commit 77c4f42

Browse files
authored
fix: compare bootconfig against previous value (#641)
1 parent 0441a6e commit 77c4f42

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

nutanix/resource_nutanix_virtual_machine.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,12 @@ func resourceNutanixVirtualMachineUpdate(ctx context.Context, d *schema.Resource
11771177
}
11781178

11791179
res.PowerStateMechanism = pw
1180-
if bc, change := bootConfigHasChange(res.BootConfig, d); !reflect.DeepEqual(*bc, v3.VMBootConfig{}) {
1181-
res.BootConfig = bc
1180+
currentBootConfig := &v3.VMBootConfig{}
1181+
if res.BootConfig != nil {
1182+
*currentBootConfig = *res.BootConfig
1183+
}
1184+
if newBootConfig, change := bootConfigHasChange(currentBootConfig, d); !reflect.DeepEqual(*newBootConfig, *currentBootConfig) {
1185+
res.BootConfig = newBootConfig
11821186
hotPlugChange = change
11831187
}
11841188

@@ -1251,19 +1255,20 @@ func getVMSpecVersion(conn *v3.Client, vmID string) (*int64, error) {
12511255
func bootConfigHasChange(boot *v3.VMBootConfig, d *schema.ResourceData) (*v3.VMBootConfig, bool) {
12521256
hotPlugChange := false
12531257

1254-
if boot == nil {
1255-
boot = &v3.VMBootConfig{}
1258+
bootConfig := &v3.VMBootConfig{}
1259+
if boot != nil {
1260+
*bootConfig = *boot
12561261
}
12571262

12581263
if d.HasChange("boot_device_order_list") {
12591264
_, n := d.GetChange("boot_device_order_list")
1260-
boot.BootDeviceOrderList = expandStringList(n.([]interface{}))
1265+
bootConfig.BootDeviceOrderList = expandStringList(n.([]interface{}))
12611266
hotPlugChange = false
12621267
}
12631268

12641269
if d.HasChange("boot_type") {
12651270
_, n := d.GetChange("boot_type")
1266-
boot.BootType = utils.StringPtr(n.(string))
1271+
bootConfig.BootType = utils.StringPtr(n.(string))
12671272
hotPlugChange = false
12681273
}
12691274

@@ -1284,13 +1289,13 @@ func bootConfigHasChange(boot *v3.VMBootConfig, d *schema.ResourceData) (*v3.VMB
12841289
bd.MacAddress = utils.StringPtr(n.(string))
12851290
hotPlugChange = false
12861291
}
1287-
boot.BootDevice = bd
1292+
bootConfig.BootDevice = bd
12881293

12891294
if dska.AdapterType == nil && dska.DeviceIndex == nil && bd.MacAddress == nil {
1290-
boot.BootDevice = nil
1295+
bootConfig.BootDevice = nil
12911296
}
12921297

1293-
return boot, hotPlugChange
1298+
return bootConfig, hotPlugChange
12941299
}
12951300

12961301
func changePowerState(ctx context.Context, conn *v3.Client, id string, powerState string) error {

0 commit comments

Comments
 (0)