terraform-provider-vsphere icon indicating copy to clipboard operation
terraform-provider-vsphere copied to clipboard

`r/virtual_machine`: add ability to configure boot sequence

Open ravik694 opened this issue 4 years ago • 5 comments

Description

It would be nice to have the ability to set the VM boot sequence through the vsphere_virtual_machine resource.

I've attempted setting this through the extra_config argument with the bios.bootOrder / bios.hddOrder parameters but the changes don't "stick" after applying the config. The same thing happens when trying to set the options through the ESXi web UI (VM -> Edit -> VM Options -> Advanced -> Edit Configuration.) The settings disappear after clicking Save. The settings do seem to be honored when I manually edit the .vmx file of the VM on the ESXi server.

Current example (extra_config settings are shown in terrraform plan and terraform apply but are not reflected in the VM config on ESXi):

resource "vsphere_virtual_machine" "vm" {
  name             = "terraform-test"
  resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"

  num_cpus = 2
  memory   = 1024
  guest_id = "other3xLinux64Guest"

  network_interface {
    network_id = "${data.vsphere_network.network.id}"
  }

  disk {
    label = "disk0"
    size  = 20

  cdrom {
    datastore_id = data.vsphere_datastore.datastore.id
    path         = "iso/linux.iso"
  }

  extra_config = {
    "bios.bootOrder" = "cdrom,hdd"
    "bios.hddOrder"  = "scsi0:0"
  }
}

Potential Terraform Configuration

resource "vsphere_virtual_machine" "vm" {
  name             = "terraform-test"
  resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"

  num_cpus = 2
  memory   = 1024
  guest_id = "other3xLinux64Guest"

  bootOrder = "floppy,cdrom,ethernet,disk"

  network_interface {
    network_id = "${data.vsphere_network.network.id}"
  }

  disk {
    label = "disk0"
    size  = 20

  cdrom {
    datastore_id = data.vsphere_datastore.datastore.id
    path         = "iso/linux.iso"
  }
}

References

My ESXi server (paid license) details:

Version: 6.7.0 Update 3 (Build 15160138)

State: Normal (not connected to any vCenter Server)

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

ravik694 avatar Dec 04 '21 01:12 ravik694

is there any update on this

thatsk avatar Nov 16 '22 04:11 thatsk

Status can be viewed in the attached milestone; however, community contributions are welcome and help to accelerate features.

tenthirtyam avatar Nov 16 '22 05:11 tenthirtyam

Some additional info from a working custom module (not Terraform, not Go):

The supported API way of configuring the boot order is via VirtualMachineBootOptions(vim.vm.BootOptions) in VirtualMachineConfigSpec(vim.vm.ConfigSpec). This works both at creation time as well as during reconfiguration.

BootOptions allow setting additional very useful booleans, that should also be exposed by the provider, most notably, bootDelay, efiSecureBootEnabled, networkBootProtocol (PXE over IPv4 or IPv6). The bootOrder array can only be populated with full knowledge of the deviceKeys of the underlying bootable device.

References

  • https://vdc-repo.vmware.com/vmwb-repository/dcr-public/c476b64b-c93c-4b21-9d76-be14da0148f9/04ca12ad-59b9-4e1c-8232-fd3d4276e52c/SDK/vsphere-ws/docs/ReferenceGuide/vim.vm.BootOptions.html

kevemueller avatar Mar 19 '23 20:03 kevemueller

The behaviour of VMs created by this provider is non-deterministic and without this feature implemented cannot be made deterministic. If you create an EFI VM with only NICs and then make Terraform reconfigure it to have NICs and CDs, the boot order will be first NIC, then CD. If you create an EFI VM with NICs and CDs, the boot order will be first CD, then NIC. This breaks one of the promises of Terraform to ensure a consistent target state.

Tested with Terraform v1.4.0, vsphere v2.3.1 against ESXi-7.0U3j-21053776-standard.

kevemueller avatar Mar 19 '23 21:03 kevemueller

Some additional info from a working custom module (not Terraform, not Go):

The supported API way of configuring the boot order is via VirtualMachineBootOptions(vim.vm.BootOptions) in VirtualMachineConfigSpec(vim.vm.ConfigSpec). This works both at creation time as well as during reconfiguration.

BootOptions allow setting additional very useful booleans, that should also be exposed by the provider, most notably, bootDelay, efiSecureBootEnabled, networkBootProtocol (PXE over IPv4 or IPv6). The bootOrder array can only be populated with full knowledge of the deviceKeys of the underlying bootable device.

References

  • https://vdc-repo.vmware.com/vmwb-repository/dcr-public/c476b64b-c93c-4b21-9d76-be14da0148f9/04ca12ad-59b9-4e1c-8232-fd3d4276e52c/SDK/vsphere-ws/docs/ReferenceGuide/vim.vm.BootOptions.html

Secure boot is exposed in vsphere_virtual_machine, a good starting point would probably be looking there to make a pr. Looking at this this is acutally a trival patch and just needs the schema updated with the exposed boot options in govmomi.

Basically add to schema in virtual_machine_config_structure.go, change https://github.com/vmware/govmomi/blob/6687830863b6607134e359991c48fd758fc8f9ed/govc/device/boot.go#L42 to add the new schema options.

nwmcsween avatar Mar 20 '23 17:03 nwmcsween