Terraform v0.11.7
resource "azurerm_virtual_machine" "build" {
  name                  = "build"
  location              = "${azurerm_resource_group.build.location}"
  resource_group_name   = "${azurerm_resource_group.build.name}"
  network_interface_ids = ["${azurerm_network_interface.build.id}"]
  vm_size               = "${var.instance_type}"
  storage_image_reference {
    id = "${data.azurerm_image.image.id}"
  }
  storage_os_disk {
    name              = "build-os"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }
  # swap
  storage_data_disk {
    name              = "build-swap"
    managed_disk_type = "Standard_LRS"
    create_option     = "Empty"
    lun               = 0
    disk_size_gb      = "${var.swap_size}"
  }
The generated plan after an image change:
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
-/+ module.server.azurerm_virtual_machine.server[0] (new resource required)
      id:                                                                 "/subscriptions/SUBSCRIPTION_ID/resourceGroups/xxxx-dev-michael-server/providers/Microsoft.Compute/virtualMachines/server-0" => <computed> (forces new resource)
      availability_set_id:                                                "/subscriptions/SUBSCRIPTION_ID/resourcegroups/xxxx-dev-michael-server/providers/microsoft.compute/availabilitysets/server" => "/subscriptions/SUBSCRIPTION_ID/resourcegroups/xxxx-dev-michael-server/providers/microsoft.compute/availabilitysets/server"
      delete_data_disks_on_termination:                                   "false" => "false"
      delete_os_disk_on_termination:                                      "false" => "false"
      identity.#:                                                         "1" => "1"
      identity.0.principal_id:                                            "204223fb-384e-4cba-839b-697067eb18e0" => <computed>
      identity.0.type:                                                    "SystemAssigned" => "SystemAssigned"
      location:                                                           "eastus" => "eastus"
      name:                                                               "server-0" => "server-0"
      network_interface_ids.#:                                            "1" => "1"
      network_interface_ids.0:                                            "/subscriptions/SUBSCRIPTION_ID/resourceGroups/xxxx-dev-michael-server/providers/Microsoft.Network/networkInterfaces/server-0" => "/subscriptions/SUBSCRIPTION_ID/resourceGroups/xxxx-dev-michael-server/providers/Microsoft.Network/networkInterfaces/server-0"
      os_profile.#:                                                       "1" => "1"
      os_profile.3437164493.admin_password:                               "" => ""
      os_profile.3437164493.admin_username:                               "toor" => ""
      os_profile.3437164493.computer_name:                                "server-0" => "" (forces new resource)
      os_profile.4290463204.admin_password:                               <sensitive> => <sensitive> (attribute changed)
      os_profile.4290463204.admin_username:                               "" => "ubuntu"
      os_profile.4290463204.computer_name:                                "" => "server-0" (forces new resource)
      os_profile.4290463204.custom_data:                                  "" => "a8e08646c1beb42ec0d36b3eaadb1e726983cbb8" (forces new resource)
      os_profile_linux_config.#:                                          "1" => "1"
      os_profile_linux_config.2972667452.disable_password_authentication: "false" => "false"
      os_profile_linux_config.2972667452.ssh_keys.#:                      "0" => "0"
      resource_group_name:                                                "xxxx-dev-michael-server" => "xxxx-dev-michael-server"
      storage_data_disk.#:                                                "1" => "1"
      storage_data_disk.0.caching:                                        "None" => <computed>
      storage_data_disk.0.create_option:                                  "Empty" => "Empty"
      storage_data_disk.0.disk_size_gb:                                   "2" => "2"
      storage_data_disk.0.lun:                                            "0" => "0"
      storage_data_disk.0.managed_disk_type:                              "Standard_LRS" => "Standard_LRS"
      storage_data_disk.0.name:                                           "server-0-swap" => "server-0-swap"
      storage_data_disk.0.write_accelerator_enabled:                      "false" => "false"
      storage_image_reference.#:                                          "1" => "1"
      storage_image_reference.2235208821.id:                              "" => "/subscriptions/SUBSCRIPTION_ID/resourceGroups/xxxx-dev-packer-images-eastus/providers/Microsoft.Compute/images/xxxx-dev-base-eastus-20180718-0" (forces new resource)
      storage_image_reference.2235208821.offer:                           "" => ""
      storage_image_reference.2235208821.publisher:                       "" => ""
      storage_image_reference.2235208821.sku:                             "" => ""
      storage_image_reference.2235208821.version:                         "" => <computed> (forces new resource)
      storage_image_reference.2879974488.id:                              "" => ""
      storage_image_reference.2879974488.offer:                           "UbuntuServer" => "" (forces new resource)
      storage_image_reference.2879974488.publisher:                       "Canonical" => "" (forces new resource)
      storage_image_reference.2879974488.sku:                             "14.04.5-LTS" => "" (forces new resource)
      storage_os_disk.#:                                                  "1" => "1"
      storage_os_disk.0.caching:                                          "ReadWrite" => "ReadWrite"
      storage_os_disk.0.create_option:                                    "FromImage" => "FromImage"
      storage_os_disk.0.disk_size_gb:                                     "30" => <computed>
      storage_os_disk.0.managed_disk_id:                                  "/subscriptions/SUBSCRIPTION_ID/resourceGroups/xxxx-dev-michael-server/providers/Microsoft.Compute/disks/server-0-os" => <computed>
      storage_os_disk.0.managed_disk_type:                                "Standard_LRS" => "Standard_LRS"
      storage_os_disk.0.name:                                             "server-0-os" => "server-0-os"
      storage_os_disk.0.write_accelerator_enabled:                        "false" => "false"
      tags.%:                                                             "2" => "2"
      tags.Cluster:                                                       "server" => "server"
      tags.DC:                                                            "xxxx-dev-michael" => "xxxx-dev-michael"
      vm_size:                                                            "Standard_B1s" => "Standard_B1s"
…
module.server.azurerm_virtual_machine.server[0]: Destruction complete after 4m15s
module.server.azurerm_virtual_machine.server[0]: Creating...
  availability_set_id:                                                "" => "/subscriptions/SUBSCRIPTION_ID/resourcegroups/xxxx-dev-michael-server/providers/microsoft.compute/availabilitysets/server"
  delete_data_disks_on_termination:                                   "" => "false"
  delete_os_disk_on_termination:                                      "" => "false"
  identity.#:                                                         "" => "1"
  identity.0.principal_id:                                            "" => "<computed>"
  identity.0.type:                                                    "" => "SystemAssigned"
  location:                                                           "" => "eastus"
  name:                                                               "" => "server-0"
  network_interface_ids.#:                                            "" => "1"
  network_interface_ids.0:                                            "" => "/subscriptions/SUBSCRIPTION_ID/resourceGroups/xxxx-dev-michael-server/providers/Microsoft.Network/networkInterfaces/server-0"
  os_profile.#:                                                       "" => "1"
  os_profile.4290463204.admin_password:                               "<sensitive>" => "<sensitive>"
  os_profile.4290463204.admin_username:                               "" => "ubuntu"
  os_profile.4290463204.computer_name:                                "" => "server-0"
  os_profile.4290463204.custom_data:                                  "" => "a8e08646c1beb42ec0d36b3eaadb1e726983cbb8"
  os_profile_linux_config.#:                                          "" => "1"
  os_profile_linux_config.2972667452.disable_password_authentication: "" => "false"
  os_profile_linux_config.2972667452.ssh_keys.#:                      "" => "0"
  resource_group_name:                                                "" => "xxxx-dev-michael-server"
  storage_data_disk.#:                                                "" => "1"
  storage_data_disk.0.caching:                                        "" => "<computed>"
  storage_data_disk.0.create_option:                                  "" => "Empty"
  storage_data_disk.0.disk_size_gb:                                   "" => "2"
  storage_data_disk.0.lun:                                            "" => "0"
  storage_data_disk.0.managed_disk_type:                              "" => "Standard_LRS"
  storage_data_disk.0.name:                                           "" => "server-0-swap"
  storage_data_disk.0.write_accelerator_enabled:                      "" => "false"
  storage_image_reference.#:                                          "" => "1"
  storage_image_reference.2235208821.id:                              "" => "/subscriptions/SUBSCRIPTION_ID/resourceGroups/xxxx-dev-packer-images-eastus/providers/Microsoft.Compute/images/xxxx-dev-base-eastus-20180718-0"
  storage_image_reference.2235208821.offer:                           "" => ""
  storage_image_reference.2235208821.publisher:                       "" => ""
  storage_image_reference.2235208821.sku:                             "" => ""
  storage_image_reference.2235208821.version:                         "" => "<computed>"
  storage_os_disk.#:                                                  "" => "1"
  storage_os_disk.0.caching:                                          "" => "ReadWrite"
  storage_os_disk.0.create_option:                                    "" => "FromImage"
  storage_os_disk.0.disk_size_gb:                                     "" => "<computed>"
  storage_os_disk.0.managed_disk_id:                                  "" => "<computed>"
  storage_os_disk.0.managed_disk_type:                                "" => "Standard_LRS"
  storage_os_disk.0.name:                                             "" => "server-0-os"
  storage_os_disk.0.write_accelerator_enabled:                        "" => "false"
  tags.%:                                                             "" => "2"
  tags.Cluster:                                                       "" => "server"
  tags.DC:                                                            "" => "xxxx-dev-michael"
  vm_size:                                                            "" => "Standard_B1s"
Error: Error applying plan:
2 error(s) occurred:
* module.server.azurerm_virtual_machine.server[1]: 1 error(s) occurred:
* azurerm_virtual_machine.server.1: Code="ConflictingUserInput" Message="Disk server-1-os already exists in resource group xxxx-DEV-MICHAEL-server. Only CreateOption.Attach is supported."
* module.server.azurerm_virtual_machine.server[0]: 1 error(s) occurred:
* azurerm_virtual_machine.server.0: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=200 -- Original Error: Code="ConflictingUserInput" Message="Disk server-1-os already exists in resource group xxxx-DEV-MICHAEL-server. Only CreateOption.Attach is supported."
(note that I have a count=2 here but I've deleted the duplicate output mostly)
(available on request)
When terraform decides the VM needs to be recreated (i.e. the image changed) it knows it needs to delete and recreate the virtual_machine, but it doesn't realize that the managed disks also need to be deleted.
The VM deletion happens but the creation fails with an error:
* azurerm_virtual_machine.server.1: Code="ConflictingUserInput" Message="Disk server-1-os already exists in resource group xxxx-DEV-MICHAEL-server. Only CreateOption.Attach is supported."
* module.server.azurerm_virtual_machine.server[0]: 1 error(s) occurred:
* azurerm_virtual_machine.server.0: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=200 -- Original Error: Code="ConflictingUserInput" Message="Disk server-1-os already exists in resource group xxxx-DEV-MICHAEL-server. Only CreateOption.Attach is supported."
terraform applyterraform apply againStrangely this happens whether delete_*_disks_on_termination is set or not.
Ø
hey @Supermathie
Thanks for opening this issue :)
There's two properties within the azurerm_virtual_machine resource that do this, but they're optional/disabled by default - delete_os_disk_on_termination and delete_data_disks_on_termination; both of which will be called when the VM is destroyed (which happens as part of the re-creation). Would you be able to take a look and see if these properties solve your issue?
Thanks!
@tombuildsstuff I left that hiding at the bottom for you :D
Strangely this happens whether delete_*_disks_on_termination is set or not.
Running into this issue as well.  The delete_*_disks_on_termination option doesn't seem to help.
hi @Supermathie
Taking a look through here the azurerm_virtual_machine resource has since been superseded by the azurerm_linux_virtual_machine and azurerm_windows_virtual_machine resources. Whilst the existing azurerm_virtual_machine resource continues to be available in 2.x releases of the Provider, it's feature-frozen and thus no longer receiving any bugfixes or enhancements to maintain compatibility.
As such I'm going to close this issue for the moment - but I'd recommend looking into the azurerm_linux_virtual_machine and azurerm_windows_virtual_machine resources going forward.
On these new resources Data Disks are currently managed externally - but #6117 is tracking bringing those inline too - at which point this behaviour will be able to be configured by specifying this behaviour in the features block within the provider block. As such would you mind subscribing to #6117 for updates here?
Thanks!
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!
Most helpful comment
Running into this issue as well. The
delete_*_disks_on_terminationoption doesn't seem to help.