Deploying Multiple VMs with Multiple Managed Disks - Azure

Terrform v14.7
Azurerm v2.48.0

I followed a great blog by Neal Shah to create multiple disks on multiple VMs.
Neal Shah - deploying-multiple-vms-with-multiple-managed-disks

Creating multiple VMs with multiple managed disks works well but I receive errors when trying to attach the managed disks to the VMs.

Error: Invalid index
on vmcountcreate.tf line 75, in resource “azurerm_virtual_machine_data_disk_attachment” “managed_disk_attach”:
75: virtual_machine_id = azurerm_windows_virtual_machine.vm[element(split(“_”, each.key), 1)].id
|----------------
| azurerm_windows_virtual_machine.vm is tuple with 2 elements
| each.key is “datadisk_vm1_disk00”

The given key does not identify an element in this collection value: a number
is required.

Line 75 in question is:

virtual_machine_id = azurerm_windows_virtual_machine.vm[element(split(“_”, each.key), 1)].id`

When I use terraform console, I am able to successfully split and use the element.

Terraform console
element(split(“_”, “datadisk_vm1_disk00”), 1)
“vm1”

I’m unsure if this is a bug or syntax issue

Thanks,

Sam