Disconnect cdrom in vshpere VM after finishing provisioning


I’m using vspher_virtual_machine and ova template to provision virtual machines on vSphere.
One issue that I have is that the CD-ROM devices do not get disconnected after the provisioning has finished.

Any ideas how I can do that through terraform, if it’s possible?

This is a snippet from the vsphere_virtual_machine resource:

	cdrom {
		client_device = true

	clone {
		template_uuid = data.vsphere_virtual_machine.template.id
		customize {
			linux_options {
				host_name = var.hostname
				domain = "localhost"

			network_interface {
				ipv4_address = var.ip_address
				ipv4_netmask = "24"

			ipv4_gateway = var.gateway
			dns_server_list = var.dns_server_list

	vapp {
		properties = {
			user-data = base64encode(var.cloudinit_config)
			"hostname" = var.hostname

I needed to set client_device in order to pass the information (cloud-init) to the virtual machine.

It seems that simply adding eject -r at the end of the cloud-init scripts does the trick. It disconnects the cd-rom it and doesn’t get connected anymore afterwards, not even after reboot.
I’ve also added these two parameters that automatically disconnects the cdrom even if vSphere thinks the virtual machine still uses it:

        extra_config = {
                "cdrom.showIsoLockWarning" = "FALSE"
                "msg.autoanswer" = "TRUE"

Reference: VMware Knowledge Base