danilo-patrucco
Contributor
Contributor

Guest OS customization using Terraform - fail on first boot

Hello, 

I am using Terraform to deploy a vm exported from AWS.

The process is the following: 

- I use Packer to build an AMI in AWS

- The ami is then exported in vmdk format to VMware using terraform ( using a clone from an s3 bucket into a datastore ) 

- a template was previously created and using terraform the template is used to create a vm, the template does not have disks attached, the disk are attached when the vm is created.

When the vm is started it fails with the following error: 

Customization of the guest operating system is not supported due to the given reason: Tools is not installed in the GuestOS. Please install the latest version of open-vm-tools or VMware Tools to enable GuestCustomization.

If I delete the VM (not remove the disk, using the Remove from inventory command) and rerun the terraform apply command it boot the vm and it is able to customize without any problem.

 

resource "vsphere_virtual_machine" "vm" {
  name             = "test_machine_vm_01"
  resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
  datastore_id     = data.vsphere_datastore.datastore.id
  folder           = "test"
  num_cpus         = data.vsphere_virtual_machine.template.num_cpus
  memory           = data.vsphere_virtual_machine.template.memory
  guest_id         = "rhel7_64Guest"
  scsi_type                               = data.vsphere_virtual_machine.template.scsi_type
  tools_upgrade_policy                    = "upgradeAtPowerCycle"
  run_tools_scripts_after_power_on        = true
  run_tools_scripts_after_resume          = true
  run_tools_scripts_before_guest_shutdown = true
  run_tools_scripts_before_guest_standby  = true
  network_interface {
    network_id   = data.vsphere_network.network.id
    adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0]
  }
  disk {
    attach       = true
    path         = var.VMDK_PATH_DISK_1
    label        = "disk.0"
    datastore_id = data.vsphere_datastore.datastore.id
  }
  disk {
    attach       = true
    path         = var.VMDK_PATH_DISK_2
    label        = "disk.1"
    datastore_id = data.vsphere_datastore.datastore.id
    unit_number  = 1
  }
  clone {
    template_uuid = data.vsphere_virtual_machine.template.id
    customize {
      linux_options {
        host_name = "rhel7-image"
        domain    = "mipa.med.ds.osd.mil"
      }
      network_interface {
        ipv4_address = "myip"
        ipv4_netmask = 24
      }
      ipv4_gateway = "mygateway"
    }
  }
}

 

In my image created with packer I use the following commands as root before shutting it down 

 

systemctl enable vmtoolsd
systemctl start vmtoolsd
systemctl status vmtoolsd

 

Any help would be appreciated.

Thank you ! 

Labels (3)
Tags (3)
0 Kudos
0 Replies