terraformvsphere

error cloning virtual machine: timeout waiting for clone to complete


I am currently using Terraform to deploy multiples vm to my vsphere. The problem is I am using clone statement to set static ip in my vms and I got the following error: error cloning virtual machine: timeout waiting for clone to complete

I am currently using terraform version v0.11.7 and my vsphere version is 6.5

resource "vsphere_virtual_machine" "master" {

  guest_id = "${data.vsphere_virtual_machine.template.guest_id}" 
resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"

count = "${length(var.vms_master)}"

network_interface {
    network_id = "${data.vsphere_network.network.id}"
    adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}"
}

  name = "${var.vms_master[count.index]}"
  datastore_id = "${data.vsphere_datastore.datastore.id}"

  disk {
    label="default_disk"
    size             = "${data.vsphere_virtual_machine.template.disks.0.size}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
    unit_number=0  
}

  disk {
      size = "100"
      label = "${var.vms_master[count.index]}_1"
      thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
      eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
        unit_number=2   
 }
  disk {
      size = "10"
      label = "${var.vms_master[count.index]}_2"
      thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
      eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
        unit_number=3   
 }

  folder = "${vsphere_folder.master.path}"
  memory = 512
  num_cpus = 1
  wait_for_guest_ip_timeout = "0" #el laboratorio va muy lento... entonces el timeout se da antes de q la vm este creada!
  wait_for_guest_net_timeout = "0"

clone {
    template_uuid = "${data.vsphere_virtual_machine.template.id}"
    linked_clone  = "${var.vm_linked_clone}"

    customize {
      //timeout = "0"
  timeouts {
    create = "5s"
    delete = "2h"
  }
      linux_options {
        host_name = "${var.vms_hostname_master[count.index]}"
        domain    = "$ocp.essi.lab"
      }
      network_interface {
        ipv4_address = "${var.ip_list_master[count.index]}"          
        ipv4_netmask = "24"
      }

      ipv4_gateway    ="172.16.1.1"
      dns_server_list = ["${var.dns_servers}"]
    }   
}
}

Expected results: Deployed vm to vsphere

Actual results: Aforementined error: error cloning virtual machine: timeout waiting for clone to complete

Thank you guys any insight is welcome! :)


Solution

  • The workaround was very simple, I only had to add one more timeout line:

    resource "vsphere_virtual_machine" "master" {
    
      guest_id = "${data.vsphere_virtual_machine.template.guest_id}" 
    resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
    datastore_id = "${data.vsphere_datastore.datastore.id}"
    
    count = "${length(var.vms_master)}"
    
    network_interface {
        network_id = "${data.vsphere_network.network.id}"
        adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}"
    }
    
      name = "${var.vms_master[count.index]}"
      datastore_id = "${data.vsphere_datastore.datastore.id}"
    
      disk {
        label="default_disk"
        size             = "${data.vsphere_virtual_machine.template.disks.0.size}"
        eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
        thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
        unit_number=0  
    }
    
      disk {
          size = "100"
          label = "${var.vms_master[count.index]}_1"
          thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
          eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
            unit_number=2   
     }
      disk {
          size = "10"
          label = "${var.vms_master[count.index]}_2"
          thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
          eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
            unit_number=3   
     }
    
      folder = "${vsphere_folder.master.path}"
      memory = 512
      num_cpus = 1
      wait_for_guest_ip_timeout = "0" #el laboratorio va muy lento... entonces el timeout se da antes de q la vm este creada!
      wait_for_guest_net_timeout = "0"
    
    clone {
        template_uuid = "${data.vsphere_virtual_machine.template.id}"
        linked_clone  = "${var.vm_linked_clone}"
          timeout = "0"   //NEW LINE ADDED
    
        customize {
          timeout = "0"
      timeouts {
        create = "5s"
        delete = "2h"
      }
          linux_options {
            host_name = "${var.vms_hostname_master[count.index]}"
            domain    = "$ocp.essi.lab"
          }
          network_interface {
            ipv4_address = "${var.ip_list_master[count.index]}"          
            ipv4_netmask = "24"
          }
    
          ipv4_gateway    ="172.16.1.1"
          dns_server_list = ["${var.dns_servers}"]
        }   
    }
    }