vsphere/resource_vsphere_virtual_machine.go
func resourceVSphereVirtualMachineUpdateReconfigureWithSDRS(
	d *schema.ResourceData,
	meta interface{},
	vm *object.VirtualMachine,
	spec types.VirtualMachineConfigSpec,
) error {
	// Check to see if we have any disk creation operations first, as sending an
	// update through SDRS without any disk creation operations will fail.
	if !storagepod.HasDiskCreationOperations(spec.DeviceChange) {
		log.Printf("[DEBUG] No disk operations for reconfiguration of VM %q, deferring to standard API", vm.InventoryPath)
		return virtualmachine.Reconfigure(vm, spec)
	}

	client := meta.(*VSphereClient).vimClient
	if err := viapi.ValidateVirtualCenter(client); err != nil {
		return fmt.Errorf("connection ineligible to use datastore_cluster_id: %s", err)
	}

	log.Printf("[DEBUG] %s: Reconfiguring virtual machine through Storage DRS API", resourceVSphereVirtualMachineIDString(d))
	pod, err := storagepod.FromID(client, d.Get("datastore_cluster_id").(string))
	if err != nil {
		return fmt.Errorf("error getting datastore cluster: %s", err)
	}

	err = storagepod.ReconfigureVM(client, vm, spec, pod)
	if err != nil {
		return fmt.Errorf("error reconfiguring VM on datastore cluster %q: %s", pod.Name(), err)
	}
	return nil
}
func resourceVSphereVirtualMachineUpdateReconfigureWithSDRS(
	d *schema.ResourceData,
	meta interface{},
	vm *object.VirtualMachine,
	spec types.VirtualMachineConfigSpec,
) error {
	// Check to see if we have any disk creation operations first, as sending an
	// update through SDRS without any disk creation operations will fail.
	if !storagepod.HasDiskCreationOperations(spec.DeviceChange) {
		log.Printf("[DEBUG] No disk operations for reconfiguration of VM %q, deferring to standard API", vm.InventoryPath)
		return virtualmachine.Reconfigure(vm, spec)
	}

	client := meta.(*VSphereClient).vimClient
	if err := viapi.ValidateVirtualCenter(client); err != nil {
		return fmt.Errorf("connection ineligible to use datastore_cluster_id: %s", err)
	}

	log.Printf("[DEBUG] %s: Reconfiguring virtual machine through Storage DRS API", resourceVSphereVirtualMachineIDString(d))
	pod, err := storagepod.FromID(client, d.Get("datastore_cluster_id").(string))
	if err != nil {
		return fmt.Errorf("error getting datastore cluster: %s", err)
	}

	err = storagepod.ReconfigureVM(client, vm, spec, pod)
	if err != nil {
		return fmt.Errorf("error reconfiguring VM on datastore cluster %q: %s", pod.Name(), err)
	}
	return nil
}
func resourceVSphereVirtualMachineUpdateReconfigureWithSDRS ( d * schema . ResourceData , meta interface { } , vm * object . VirtualMachine , spec types . VirtualMachineConfigSpec , ) error { // Check to see if we have any disk creation operations first, as sending an // update through SDRS without any disk creation operations will fail. if ! storagepod . HasDiskCreationOperations ( spec . DeviceChange ) { log . Printf ( " " , vm . InventoryPath ) return virtualmachine . Reconfigure ( vm , spec ) } client := meta . ( * VSphereClient ) . vimClient if err := viapi . ValidateVirtualCenter ( client ) ; err != nil { return fmt . Errorf ( " " , err ) } log . Printf ( " " , resourceVSphereVirtualMachineIDString ( d ) ) pod , err := storagepod . FromID ( client , d . Get ( " " ) . ( string ) ) if err != nil { return fmt . Errorf ( " " , err ) } err = storagepod . ReconfigureVM ( client , vm , spec , pod ) if err != nil { return fmt . Errorf ( " " , pod . Name ( ) , err ) } return nil }
// resourceVSphereVirtualMachineUpdateReconfigureWithSDRS runs the reconfigure
// part of resourceVSphereVirtualMachineUpdate through storage DRS. It's
// designed to be run when a storage cluster is specified, versus simply
// specifying datastores.
resourceVSphereVirtualMachineUpdateReconfigureWithSDRS runs the reconfigure part of resourceVSphereVirtualMachineUpdate through storage DRS . It s designed to be run when a storage cluster is specified versus simply specifying datastores .