Skip to content

Commit

Permalink
fix: errored boot config validation on vm update
Browse files Browse the repository at this point in the history
  • Loading branch information
marinsalinas committed Oct 21, 2020
1 parent df0472e commit 38082c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 13 additions & 4 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ func resourceNutanixVirtualMachine() *schema.Resource {
},
"boot_device_order_list": {
Type: schema.TypeList,
// remove MaxItems when the issue #28 is fixed
MaxItems: 1,
// // remove MaxItems when the issue #28 is fixed
// MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -987,6 +987,7 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{})
mac := ""
b := make([]string, 0)

log.Printf("[DEBUG] checking BootConfig %+v", resp.Status.Resources.BootConfig)
if resp.Status.Resources.BootConfig != nil {
if resp.Status.Resources.BootConfig.BootDevice != nil {
if resp.Status.Resources.BootConfig.BootDevice.DiskAddress != nil {
Expand All @@ -997,11 +998,15 @@ func resourceNutanixVirtualMachineRead(d *schema.ResourceData, meta interface{})
mac = utils.StringValue(resp.Status.Resources.BootConfig.BootDevice.MacAddress)
}
if resp.Status.Resources.BootConfig.BootDeviceOrderList != nil {
log.Printf("[DEBUG] checking BootConfig.BootDeviceOrderList %+v", utils.StringValueSlice(resp.Status.Resources.BootConfig.BootDeviceOrderList))
b = utils.StringValueSlice(resp.Status.Resources.BootConfig.BootDeviceOrderList)
}
}

d.Set("boot_device_order_list", b)
if err := d.Set("boot_device_order_list", b); err != nil {
return fmt.Errorf("error setting boot_device_order_list %s", err)
}

d.Set("boot_device_disk_address", diskAddress)
d.Set("boot_device_mac_address", mac)

Expand Down Expand Up @@ -1085,10 +1090,12 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{

response, err := conn.V3.GetVM(d.Id())

//prefill structs
preFillResUpdateRequest(res, response)
preFillGTUpdateRequest(guestTool, response)
preFillGUpdateRequest(guest, response)
preFillPWUpdateRequest(pw, response)
boot = res.BootConfig

if err != nil {
if strings.Contains(fmt.Sprint(err), "ENTITY_NOT_FOUND") {
Expand Down Expand Up @@ -1291,6 +1298,7 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{
res.GpuList = expandGPUList(d)
hotPlugChange = false
}

if d.HasChange("boot_device_order_list") {
_, n := d.GetChange("boot_device_order_list")
boot.BootDeviceOrderList = expandStringList(n.([]interface{}))
Expand All @@ -1316,7 +1324,7 @@ func resourceNutanixVirtualMachineUpdate(d *schema.ResourceData, meta interface{
boot.BootDevice = bd

if dska.AdapterType == nil && dska.DeviceIndex == nil && bd.MacAddress == nil {
boot = nil
boot.BootDevice = nil
}

res.PowerStateMechanism = pw
Expand Down Expand Up @@ -1975,6 +1983,7 @@ func preFillResUpdateRequest(res *v3.VMResources, response *v3.VMIntentResponse)
gold = nil
}
res.GpuList = gold

if response.Spec.Resources.BootConfig != nil {
res.BootConfig = response.Spec.Resources.BootConfig
} else {
Expand Down
6 changes: 6 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ func PrintToJSON(v interface{}, msg string) {
fmt.Print("\n", msg, string(pretty))
}

func ToJSONString(v interface{}) string {
pretty, _ := json.MarshalIndent(v, "", " ")

return string(pretty)
}

// DebugRequest ...
func DebugRequest(req *http.Request) {
requestDump, err := httputil.DumpRequest(req, true)
Expand Down

0 comments on commit 38082c0

Please sign in to comment.