Skip to content

Commit

Permalink
fix: Add conditional to avoid panic on vGPU additionl
Browse files Browse the repository at this point in the history
Adds conditional to avoid a provider panic when a vGPU is added as a PCI device outside of Terraform to a virtual machine. #1265

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
Ryan Johnson committed Mar 18, 2022
1 parent 3bc2ce9 commit 6a25d43
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,16 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
d.Set("storage_policy_id", polID)
}

// Read the PCI passthrough devices.
// Read the virtual machine PCI passthrough devices
var pciDevs []string
for _, dev := range vprops.Config.Hardware.Device {
if pci, ok := dev.(*types.VirtualPCIPassthrough); ok {
devID := pci.Backing.(*types.VirtualPCIPassthroughDeviceBackingInfo).Id
pciDevs = append(pciDevs, devID)
if pciBacking, ok := pci.Backing.(*types.VirtualPCIPassthroughDeviceBackingInfo); ok {
devId := pciBacking.Id
pciDevs = append(pciDevs, devId)
} else {
log.Printf("[DEBUG] %s: PCI passthrough device %q has no backing ID", resourceVSphereVirtualMachineIDString(d), pci.GetVirtualDevice().DeviceInfo.GetDescription())
}
}
}
err = d.Set("pci_device_id", pciDevs)
Expand Down

0 comments on commit 6a25d43

Please sign in to comment.