terra-farm/terraform-provider-virtualbox

VM create failure when network adapter is taking long time to initialize

leodotcloud opened this issue · 5 comments

For some reason, the network adapter in my VM on my machine is taking longer time to start and that's causing failure in terraform create.

OS Details:

uname -a
Darwin Macbook.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64 x86_64

Log:

virtualbox_vm.node[0]: Creating...
virtualbox_vm.node[0]: Still creating... [10s elapsed]
virtualbox_vm.node[0]: Still creating... [20s elapsed]
virtualbox_vm.node[0]: Still creating... [30s elapsed]
virtualbox_vm.node[0]: Still creating... [40s elapsed]
╷
│ Error: [ERROR] Wait VM until ready: waiting for VM (node-01) to become ready: [ERROR] can't convert vbox network to terraform data: No match with get guestproperty output
│
│   with virtualbox_vm.node[0],
│   on infra.tf line 10, in resource "virtualbox_vm" "node":
│   10: resource "virtualbox_vm" "node" {
│
terraform {
  required_providers {
    virtualbox = {
      source = "leodotcloud/virtualbox"
      version = "0.0.3"
    }
  }
}

resource "virtualbox_vm" "node" {
  count     = 1
  name      = format("node-%02d", count.index + 1)
  image     = "https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20210916.0.0/providers/virtualbox.box"
  cpus      = 2
  memory    = "4096 mib"
  #user_data = file("user_data")

  network_adapter {
    type           = "hostonly"
    host_interface = "vboxnet0"
  }
}

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)
}

Code: https://github.com/terra-farm/terraform-provider-virtualbox/blob/v0.2.1-alpha.1/virtualbox/resource_vm.go#L503

Looks like there is only a 3 second hardcoded timeout. Is it possible to make this configurable?

Closing this issue as the PR has been merged. Fix available in release 0.2.2-alpha.1.

### Error: [ERROR] Wait VM until ready: waiting for VM (node-01) to become ready: [ERROR] can't convert vbox network to terraform data: No match with get guestproperty output

terraform {
required_providers {
virtualbox = {
source = "terra-farm/virtualbox"
version = "0.2.2-alpha.1"
}
}
}

resource "virtualbox_vm" "node" {
count = 1
name = format("node-%02d", count.index + 1)
image = "https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20210916.0.0/providers/virtualbox.box"
cpus = 1
memory = "1024 mib"
user_data = file("${path.module}/user_data")

network_adapter {
type = "nat"
}
network_adapter {
type = "bridged"
host_interface = "eno1"
}

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)
}

As I see the latest version 0.2.2-alpha.1 is waiting about 30 seconds for initialization of network interfaces. It should be enough to get VM ready.
It's not mentioned as a requirement but you must have working DHCP in your physical local network or in your VirtualBox environment. And the first thing we need to check is how your VM is getting IP address from it. Does it take more than 30s?

its getting ip address from the router dhcp

is there a way to check the vm completely ready then check
or
can we have a wait time variable in terraform that we can specify