func powerOnAndWait(d *schema.ResourceData, vm *vbox.Machine, meta interface{}) error {
	if err := vm.Start(); err != nil {
		return err
	}

	return WaitUntilVMIsReady(d, vm, meta)
}
func tf_to_vbox(d *schema.ResourceData, vm *vbox.Machine) error {
	var err error
	vm.OSType = "Linux_64"
	vm.CPUs = uint(d.Get("cpus").(int))
	bytes, err := humanize.ParseBytes(d.Get("memory").(string))
	vm.Memory = uint(bytes / humanize.MiByte) // VirtualBox expect memory to be in MiB units
	if err != nil {
		return err
	}
	vm.VRAM = 20 // Always 10MiB for vram
	vm.Flag = vbox.F_acpi | vbox.F_ioapic | vbox.F_rtcuseutc | vbox.F_pae |
		vbox.F_hwvirtex | vbox.F_nestedpaging | vbox.F_largepages | vbox.F_longmode |
		vbox.F_vtxvpid | vbox.F_vtxux
	vm.BootOrder = []string{"disk", "none", "none", "none"}
	vm.NICs, err = net_tf_to_vbox(d)
	userData := d.Get("user_data").(string)
	if userData != "" {
		err = vm.SetExtraData("user_data", userData)
	}
	return err
}
func net_vbox_to_tf(vm *vbox.Machine, d *schema.ResourceData) error {
	vbox_to_tf_network_type := func(netType vbox.NICNetwork) string {
		switch netType {
		case vbox.NICNetBridged:
			return "bridged"
		case vbox.NICNetNAT:
			return "nat"
		case vbox.NICNetHostonly:
			return "hostonly"
		case vbox.NICNetInternal:
			return "internal"
		case vbox.NICNetGeneric:
			return "generic"
		default:
			return ""
		}
	}

	vbox_to_tf_vdevice := func(vdevice vbox.NICHardware) string {
		switch vdevice {
		case vbox.AMDPCNetPCIII:
			return "PCIII"
		case vbox.AMDPCNetFASTIII:
			return "FASTIII"
		case vbox.IntelPro1000MTDesktop:
			return "IntelPro1000MTDesktop"
		case vbox.IntelPro1000TServer:
			return "IntelPro1000TServer"
		case vbox.IntelPro1000MTServer:
			return "IntelPro1000MTServer"
		default:
			return ""
		}
	}

	/* Collect NIC data from guest OS, available only when VM is running */
	if vm.State == vbox.Running {
		/* NICs in guest OS (eth0, eth1, etc) does not neccessarily have save
		order as in VirtualBox (nic1, nic2, etc), so we use MAC address to setup a mapping */
		type OsNicData struct {
			ipv4Addr string
			status   string
		}
		osNicMap := make(map[string]OsNicData) // map from MAC address to data

		var errs []error

		for i := 0; i < len(vm.NICs); i++ {
			var osNic OsNicData

			/* NIC MAC address */
			macAddr, err := vm.GetGuestProperty(fmt.Sprintf("/VirtualBox/GuestInfo/Net/%d/MAC", i))
			if err != nil {
				errs = append(errs, err)
				continue
			}
			if macAddr == nil || *macAddr == "" {
				return nil
			}

			/* NIC status */
			status, err := vm.GetGuestProperty(fmt.Sprintf("/VirtualBox/GuestInfo/Net/%d/Status", i))
			if err != nil {
				errs = append(errs, err)
				continue
			}
			if status == nil || *status == "" {
				return nil
			}
			osNic.status = strings.ToLower(*status)

			/* NIC ipv4 address */
			ipv4Addr, err := vm.GetGuestProperty(fmt.Sprintf("/VirtualBox/GuestInfo/Net/%d/V4/IP", i))
			if err != nil {
				errs = append(errs, err)
				continue
			}
			if ipv4Addr == nil || *ipv4Addr == "" {
				return nil
			}
			osNic.ipv4Addr = *ipv4Addr

			osNicMap[*macAddr] = osNic
		}

		if len(errs) > 0 {
			return &multierror.Error{Errors: errs}
		}

		/* Assign NIC property to vbox structure and Terraform */
		nics := make([]map[string]interface{}, 0, 1)

		for _, nic := range vm.NICs {
			out := make(map[string]interface{})

			out["type"] = vbox_to_tf_network_type(nic.Network)
			out["device"] = vbox_to_tf_vdevice(nic.Hardware)
			out["host_interface"] = nic.HostInterface
			out["mac_address"] = nic.MacAddr

			osNic, ok := osNicMap[nic.MacAddr]
			if !ok {
				return nil
			}
			out["status"] = osNic.status
			out["ipv4_address"] = osNic.ipv4Addr
			if osNic.ipv4Addr == "" {
				out["ipv4_address_available"] = "no"
			} else {
				out["ipv4_address_available"] = "yes"
			}

			nics = append(nics, out)
		}

		d.Set("network_adapter", nics)
	} else {
		/* Assign NIC property to vbox structure and Terraform */
		nics := make([]map[string]interface{}, 0, 1)

		for _, nic := range vm.NICs {
			out := make(map[string]interface{})

			out["type"] = vbox_to_tf_network_type(nic.Network)
			out["device"] = vbox_to_tf_vdevice(nic.Hardware)
			out["host_interface"] = nic.HostInterface
			out["mac_address"] = nic.MacAddr

			out["status"] = "down"
			out["ipv4_address"] = ""
			out["ipv4_address_available"] = "no"

			nics = append(nics, out)
		}

		d.Set("network_adapter", nics)
	}

	return nil
}