Example Usage

resource "virtualbox_vm" "node" {
  count     = 2
  name      = format("node-%02d", count.index + 1)
  image     = ""
  cpus      = 2
  memory    = "512 mib"
  user_data = file("user_data")

  network_adapter {
    type           = "hostonly"
    host_interface = "vboxnet1"

output "IPAddr" {
  value = element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, 1)

output "IPAddr_2" {
  value = element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, 2)

Argument Reference

  • name - string, required: The name of the virtual machine.

  • image, string, required: The place of the image file (archive or vagrant box). This can be a remote resource (http/https), or local location. (ex. Ubuntu Virtualbox image)

  • url, DEPRECATED - USE image, string, optional, default not set: The url for downloaded vagrant box from external resource. Overrides image if set.

  • cpus, int, optional, default=2: The number of CPUs.

  • memory, string, optional, default="512mib": The size of memory, allow human friendly units like 'MB', 'MiB'.

  • user_data, string, optional, default="": User defined data.

  • status, string, optional, default="running": The status of the VM, allowed values: 'poweroff', 'running'. This value will be updated at runtime to reflect the real status of the VM, and you can also specify it explicitly in config to manually control the status of the VM. This value defaults to 'running', so terraform apply will always try to keep the VM running if not specified otherwise.

  • network_adapter, list: The network adapters in the VM, you can have up to 4 adapters.

    • .#.type, string, requried: The type of the network, allowed values: 'nat', 'bridged', 'hostonly', 'internal', 'generic'.

    • .#.device, string, optional, default="IntelPro1000MTServer": The model of the virtual hardware device, allowed values: PCIII, FASTIII, IntelPro1000MTDesktop, IntelPro1000TServer, IntelPro1000MTServer.

    • .#.host_interface, string, optional: Some network type (hostonly, bridged, etc) must bind to a host interface to work properly, use this field to specify the name of the host interface you like to bind to (like 'en0', 'eth1', 'wlan', etc). This should get an improvement, see [TODO](#todo) section below.

    • .#.status, string, computed: The status of the network adapter, possible values: 'up', 'down'.

    • .#.mac_address, string, computed: The MAC address of the adapter, this is generated by VirtualBox.

    • .#.ipv4_address, string, computed: The IPv4 address assigned to the adapter.

    • .#.ipv4_address_available, string, computed: Wheather or not an IPv4 address is actaully assigned to the adapter, possible values: "yes", "no".

  • optical_disks, list: The iso image to attach.

Network adapter types

  • NAT

  • bridged