Hi,
I have the following code :-
resource "azurerm_virtual_machine" "elastic_uk" {
count = 3
name = "uks-elastic-vm-${count.index}"
location = "${azurerm_resource_group.elastic_uk.location}"
network_interface_ids = ["${element(azurerm_network_interface.elastic_uk.*.id,count.index)}"]
vm_size = "Standard_E2s_v3"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
#name = "uks-elastic-vm-${azurerm_virtual_machine.elastic_uk.*.count.index}-disk-os"
name = "uks-elastic-vm-${count.index}-disk-os"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
However, this throws 3 errors.
3 error(s) occurred:
* azurerm_virtual_machine.elastic_uk[0]: 1 error(s) occurred:
* azurerm_virtual_machine.elastic_uk.0: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=200 -- Original Error: Long running operation terminated with status 'Failed': Code="BadRequest" Message="Disk(s) uks-elastic-vm-0-disk-os, /subscriptions/8ea629bf-ba46-4e23-b1a7-38be2d205d77/resourceGroups/ieso-uks-elastic/providers/Microsoft.Compute/disks/uks-elastic-disk-data-0 duplicated or attached to multiple VMs."
* azurerm_virtual_machine.elastic_uk[2]: 1 error(s) occurred:
* azurerm_virtual_machine.elastic_uk.2: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: failed request: autorest/azure: Service returned an error. Status=<nil> Code="PropertyChangeNotAllowed" Message="Changing property 'osDisk.name' is not allowed."
* azurerm_virtual_machine.elastic_uk[1]: 1 error(s) occurred:
* azurerm_virtual_machine.elastic_uk.1: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: failed request: autorest/azure: Service returned an error. Status=<nil> Code="PropertyChangeNotAllowed" Message="Changing property 'osDisk.name' is not allowed."
which really don't make sense to me!?
Is my approach using element() the correct way to select the right network interface?
It's almost as if it's trying to use the same OS disk over and over for each VM, but surely terraform would know that each one is part of the VM that it relates to?
I hope this makes sense to someone.
Thanks,
Steve