hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
618 stars 452 forks source link

timeout waiting for customization to complete #739

Closed rushi47 closed 5 years ago

rushi47 commented 5 years ago

Hello Team,

So it seems that sometimes plan get completed successfully which is 1 in 100 times other time it gets timed out.

Tried everything from the previous issues, like #312 but my issue is not solved.

Tried using both as I felt its network issue :

wait_for_guest_net_routable = false wait_for_guest_net_timeout = 0

Apart from this in the logs which is inside /var/log/VMware-imc/toolsDeployPkg.log it shows:

Error code 127 for telinet, but from other observation I found that even if the plans get executed successfully error still exists in logs.

Below is the code for same, it will be great if anyone can help ASAP as its halting our automations.

provider "vsphere" {
  user           = "${var.vsphere_user}"
  password       = "${var.vsphere_password}"
  vsphere_server = "${var.vsphere_server}"

  allow_unverified_ssl = true
}
data "vsphere_datacenter" "dc" {
  name = "ZYCUS-MUM-DC"
}

data "vsphere_datastore" "datastore" {
  name          = "ESX07-LOCAL-DS01"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_compute_cluster" "cluster" {
  name          = "ZYCUS-MUM-CLUSTER02"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
  name          = "INMUZV-DDA-PACKER-TEMPLATE"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_network" "network" {
  name          = "VDS-VLAN1110-DD-A"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

resource "vsphere_virtual_machine" "vm" {
  name             = "TF Managed Server | NET"
  folder           = "TestR&D"
  wait_for_guest_net_routable = false
  wait_for_guest_net_timeout = 0
  enable_logging = true
  resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"
  network_interface = {
    network_id = "${data.vsphere_network.network.id}"
  }
  num_cpus = 1
  memory   = 1024
  guest_id = "rhel7_64Guest"
  disk {
    label            = "disk0"
    size             = "50"  
  }
  disk {
    label            = "disk1"
    size             = "50"
    unit_number      = 1
  }
  clone {

    template_uuid = "${data.vsphere_virtual_machine.template.id}"

  customize {
      linux_options {
        host_name = "terraform-test-NET"
        domain    = "test.internal"
      }
      network_interface {
          ipv4_address = "10.111.1.12"
          ipv4_netmask = 16
      }
      ipv4_gateway = "10.111.0.1"
    }
  }
}
rushi47 commented 5 years ago

@bflad, @vancluever guys can you please look into it. It will be great help.

bill-rich commented 5 years ago

@rushi47 Sorry you're running into issues with customization. Please take a look here and confirm your source VM meets the guest customization requirements. If it does, can you try cloning and customizing the VM with the same parameters through the vCenter client, and then checking the logs on the cloned VM to make sure customization is working when done manually?

rushi47 commented 5 years ago

@bill-rich, Thanks a lot for the reply, I checked the same and manually vm gets provisioned, same in case of terraform. Terraform provisions the vm, do customization, do steps defined everything. Only it gets timeout else vm customization and launching part works perfectly reason why it mark the resource as tainted. Can I know exactly what all parameter it checks for acknowledgement, i noticed that it attempts to restart the provision vm and it fails while doing so that can also be one of the case. So it will be great if you can let me know what all the steps terraform checks for the acknowledgement.

bill-rich commented 5 years ago

Once the vSphere provider sends the customization spec and powers on the VM, it waits for one of three things:

  1. CustomizationSucceeded event - This is returned via the vSphere API when guest OS customization finishes and is successful.
  2. CustomizationFailed - Returned when customization completes and fails.
  3. The amount of time specified specified in the customize timeout attribute has passed since customization started.
rushi47 commented 5 years ago

Have tried adding timeout in customization and it shows complete now. Does it mean that my provisioning was successful? Also, it seems that when am trying to output default_ip_address its outputting the blank value same even if I change it to guest_ip_addresses so its because of timeout or its the default behavior.

bill-rich commented 5 years ago

Since the Terraform is completing without errors, it means the customization is completing successfully. If the timer expires, or the CustomizationFailed event is received, the run will end with an error.

For the issue of the IP addresses not being populated, try removing wait_for_guest_net_timeout (or set it to a >0 time). Populating the IP can take a few minutes after the VM is created because the IP is pulled from VMware Tools after the operating system is up and running. Without the wait_for_guest_net_timeout option, Terraform will mark the resource as complete as soon as customization completes.