Error with storage_os_disk under azure_virtual machine

459 views
Skip to first unread message

Steve Button

unread,
Jan 24, 2018, 6:05:47 AM1/24/18
to Terraform
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}"
  resource_group_name   = "${azurerm_resource_group.elastic_uk.name}"
  network_interface_ids = ["${element(azurerm_network_interface.elastic_uk.*.id,count.index)}"]
  vm_size               = "Standard_E2s_v3"
  availability_set_id   = "${azurerm_availability_set.elastic_uk.id}"

  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

Steve Button

unread,
Jan 24, 2018, 8:26:32 AM1/24/18
to Terraform
Fixed it. Terraform had not destroyed all the resources from the previous run, even after running a destroy. It was complaining about the Resource Group not being destroyed, but it didn't mention a bunch of other stuff which was left behind. Deleted the whole RG from the Azure consule, and it's working fine. 
Reply all
Reply to author
Forward
0 new messages