Vmware vsphere - datastore ISO not connected at power on

Hi, I hope someone can help me with an issue I’m having.

I have a script to create a Windows VM with Terraform. When I try to launch the console for the VM I created, it says “Operating system not found.” Looking at the VM settings, the CD/DVD drive section has a checkbox checked for “Connect at power on.” This is supposed to connect the datastore ISO that I specified to the VM, but the ISO is not connected. I have to manually connect it and reboot the VM for it to work. We’ve built VMs through Power CLI before and did not have this problem, so I think it’s a problem with my script.
Any help would be appreciated!

My script:

resource “vsphere_virtual_machine” “vm” {
name = “terraform-test”
resource_pool_id = <resource_pool_id>
datastore_id = “${data.vsphere_datastore.datastore.id}”

num_cpus = 2
memory = 4096
guest_id = “windows8Server64Guest”

network_interface {
network_id = “${data.vsphere_network.network.id}”

disk {
label = “disk0”
size = 100

cdrom {
datastore_id = “${data.vsphere_datastore.datastore.id}”
path = <path/to/iso>

Terraform v0.15.0
on windows_amd64
provider registry.terraform.io/hashicorp/vsphere v1.26.0

Steps to Reproduce:

  1. terraform init
  2. terraform apply
  3. Open VCSA and test the VM


You just need to take care of the path, need to provide the relative path as disk name will be automatically picked.

path = <path/to/iso>