Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating r/virtual_machine with multiple PCI passthrough devices is not supported #2237

Open
4 tasks done
spacegospod opened this issue Jul 8, 2024 · 0 comments
Open
4 tasks done
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage
Milestone

Comments

@spacegospod
Copy link
Collaborator

Community Guidelines

  • I have read and agree to the HashiCorp Community Guidelines .
  • Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave "+1" or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Terraform

1.5.7

Terraform Provider

2.8.2

VMware vSphere

8.0.2

Description

I identified this problem while working on #1688

A PCI passthrough device can be added to a virtual machine only during reconfiguration. Attempting to create a virtual machine with such devices fails.

This happens because same codepath is followed both when creating and reconfiguring a virtual machine, at least as far as PCI devices are concerned.

The root cause of the problem is in the following method

https://github.com/hashicorp/terraform-provider-vsphere/blob/main/vsphere/internal/virtualdevice/virtual_machine_device_subresource.go#L974

func (c *pciApplyConfig) modifyVirtualPciDevices(devList *schema.Set, op types.VirtualDeviceConfigSpecOperation) error {
	log.Printf("VirtualMachine: Creating PCI passthrough device specs %v", op)
	for _, addDev := range devList.List() {
		log.Printf("[DEBUG] modifyVirtualPciDevices: Appending %v spec for %s", op, addDev.(string))
		pciDev, err := c.getHostPciDevice(addDev.(string))
		if err != nil {
			return err
		}
		dev := &types.VirtualPCIPassthrough{
			VirtualDevice: types.VirtualDevice{
				DynamicData: types.DynamicData{},
				Backing: &types.VirtualPCIPassthroughDeviceBackingInfo{
					VirtualDeviceDeviceBackingInfo: types.VirtualDeviceDeviceBackingInfo{},
					Id:                             pciDev.Id,
					SystemId:                       c.SystemID,
					VendorId:                       pciDev.VendorId,
				},
				Key: c.VirtualDevice.NewKey(),
			},
		}
		vm, err := virtualmachine.FromUUID(c.Client, c.ResourceData.Id())

This function attempts to retrieve the virtual machine by its identifier which is impossible before the machine has been created. The VM reference is necessary so that this method can later on loop over its devices and prepare the reconfiguration changes.

We need to define a dedicated procedure for adding PCI devices to a VM creation specification.
This will require changes to virtual_machine_device_subresource.go as well as refactoring in resource_vsphere_virtual_machine.go

Affected Resources or Data Sources

resource/vsphere_virtual_machine

Terraform Configuration

resource "vsphere_virtual_machine" "vm" {
  ...
  pci_device_id = ["any:pci:device:id"]
}

Debug Output

N/A

Panic Output

No response

Expected Behavior

A virtual machine should be created

Actual Behavior

The execution fails before the creation task is triggered

Steps to Reproduce

Attempt to create a virtual machine with at least one value for pci_device_id

Environment Details

No response

Screenshots

No response

References

No response

@spacegospod spacegospod added bug Type: Bug needs-triage Status: Issue Needs Triage labels Jul 8, 2024
@spacegospod spacegospod added this to the Backlog milestone Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage
Projects
None yet
Development

No branches or pull requests

1 participant