Getting error of reference of count in azurerm virtual machine extension resource

Hi,

I have an issue where I am passing the windows vm creation to the extension resource for domain join. It works when there is no count parameter defined in the “azurerm_windows_virtual_machine” however when I try to set a count variable it errors out with the following

on DomainJoin.tf line 33, in resource “azurerm_virtual_machine_extension” “DomainJoin”:
33: virtual_machine_id = “${element(azurerm_windows_virtual_machine.deploy_win_vm.id, count.index)}”

Because azurerm_windows_virtual_machine.deploy_win_vm has “count” set, its
attributes must be accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
azurerm_windows_virtual_machine.deploy_win_vm[count.index]

I have tried the suggested bit but it doesn’t work!