3
provider "vsphere" {
    vsphere_server = "myserver"
    user = "myuser"
    password = "mypass"
    allow_unverified_ssl = true
    version = "v1.21.0"
}

data "vsphere_datacenter" "dc" {
  name = "pcloud-datacenter"
}

data "vsphere_datastore_cluster" "datastore_cluster" {
  name          = "pc-storage"
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_compute_cluster" "compute_cluster" {
  name          = "pcloud-cluster"
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_network" "network" {
  name          = "u32c01p26-1514"
  datacenter_id = data.vsphere_datacenter.dc.id
}


data "vsphere_virtual_machine" "vm_template" {
  name          = "first-terraform-vm"
  datacenter_id = data.vsphere_datacenter.dc.id
}


resource "vsphere_virtual_machine" "vm" {
  count = 1
  name = "first-terraform-vm-1"
  resource_pool_id = data.vsphere_compute_cluster.compute_cluster.resource_pool_id
  datastore_cluster_id = data.vsphere_datastore_cluster.datastore_cluster.id

  num_cpus   = 2
  memory     = 1024

  wait_for_guest_ip_timeout = 2
  wait_for_guest_net_timeout = 0

  guest_id = data.vsphere_virtual_machine.vm_template.guest_id

  scsi_type = data.vsphere_virtual_machine.vm_template.scsi_type

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

  disk {
    name             = "disk0.vmdk"
    size             = data.vsphere_virtual_machine.vm_template.disks.0.size
    eagerly_scrub    = data.vsphere_virtual_machine.vm_template.disks.0.eagerly_scrub
    thin_provisioned = data.vsphere_virtual_machine.vm_template.disks.0.thin_provisioned
  }
  
  folder = "virtual-machines"

  clone {
    template_uuid = data.vsphere_virtual_machine.vm_template.id
   
    customize {
      linux_options {
        host_name = "first-terraform-vm-1"
        domain = "localhost.localdomain"
      }
      network_interface {
        ipv4_address = "10.10.14.100"
        ipv4_netmask = 24
      }
      ipv4_gateway = "10.10.14.1"
    }
  }
}

The command terraform script throws the below error

Error: 
Virtual machine customization failed on "/pcloud-datacenter/vm/virtual-machines/first-terraform-vm-1":

An error occurred while customizing VM first-terraform-vm-1. For details reference the log file <No Log> in the guest OS.

The virtual machine has not been deleted to assist with troubleshooting. If
corrective steps are taken without modifying the "customize" block of the
resource configuration, the resource will need to be tainted before trying
again. For more information on how to do this, see the following page:
https://www.terraform.io/docs/commands/taint.html


  on create_vm.tf line 34, in resource "vsphere_virtual_machine" "vm":
  34: resource "vsphere_virtual_machine" "vm" {


Some how the generated vm "first-terraform-vm-1" doesn't have the connected box checked-in in network settings. While i checked my template "first-terraform-vm" it has network connected box checked-in.

I see similar post in github https://github.com/hashicorp/terraform-provider-vsphere/issues/951 But not sure why this issue is still surfacing?

Vsphere version: 6.7 Terraform v0.12.28 provider.vsphere v1.21.0

Is there anything wrong with my template? Or am i missing something? Can anyone help please? Stuck with this for last 2 days.

Darshan
  • 94
  • 1
  • 8

1 Answers1

1

The problem looks to be with the template that i have used. The linux template should have Network Manager installed and running. It looks like terraform uses the network manager to assign IPaddress for newly created vm.

Darshan
  • 94
  • 1
  • 8