Terraform-provider-azurerm: azurerm_windows_virtual_machine does not support creation from image with managed data disks

Created on 5 Mar 2020  路  6Comments  路  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Reviewing the docs on the new azurerm_windows_virtual_machine resource, I dont see any reason why this shouldnt work.
We use terraform to create Windows Server images that have managed data disks.
In v0.11 with the Azure provider, when we subsequently make VMs from those images no mention of the managed disk snapshots is required....they simply come w/ the image. In v0.12 we get the following error:

Error: Error creating Windows Virtual Machine "BBVM1-vm" (Resource Group "BBVM1"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="StorageProfile.dataDisks.lun does not have required value(s) for image specified in storage profile." Target="storageProfile"
on modules\vm-base\main.tf line 47, in resource "azurerm_windows_virtual_machine" "config":
47: resource "azurerm_windows_virtual_machine" "config" {

Our old v0.11 version

resource "azurerm_virtual_machine" "config" {
  count                            = "${contains(var.servers_needed, var.computer_name) ? 1 : 0}"
  name                             = "${local.name}-vm"
  location                         = "${azurerm_resource_group.config.location}"
  license_type                     = "Windows_Server"
  resource_group_name              = "${azurerm_resource_group.config.name}"
  network_interface_ids            = ["${azurerm_network_interface.config.id}"]
  vm_size                          = "${var.virtual_machine_size}"
  delete_os_disk_on_termination    = true
  delete_data_disks_on_termination = true

  storage_image_reference {
    id = "${data.azurerm_image.search.id}"
  }

  storage_os_disk {
    name              = "${local.name}-os-disk"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "StandardSSD_LRS"
  }

  os_profile {
    computer_name  = "${local.name}"
    admin_username = "${var.admin_username}"
    admin_password = "${var.admin_password}"
  }

  os_profile_windows_config {
    provision_vm_agent        = true
    enable_automatic_upgrades = false

    additional_unattend_config {
      pass         = "oobeSystem"
      component    = "Microsoft-Windows-Shell-Setup"
      setting_name = "AutoLogon"
      content      = "<AutoLogon><Password><Value>${var.admin_password}</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount><Username>${var.admin_username}</Username></AutoLogon>"
    }

    additional_unattend_config {
      pass         = "oobeSystem"
      component    = "Microsoft-Windows-Shell-Setup"
      setting_name = "FirstLogonCommands"
      content      = "${file("${path.root}/FirstLogonCommands.xml")}"
    }
  }
}

Our new v0.12 with the current beta azurerm_windows_virtual_machine

resource "azurerm_windows_virtual_machine" "config" {
  count                 = contains(var.servers_needed, var.computer_name) ? 1 : 0
  name                  = "${local.name}-vm"
  location              = azurerm_resource_group.config[0].location
  resource_group_name   = azurerm_resource_group.config[0].name
  network_interface_ids = [azurerm_network_interface.config[0].id]
  size                  = var.virtual_machine_size
  source_image_id       = data.azurerm_image.search.id
  computer_name         = local.name
  admin_username        = var.admin_username
  admin_password        = var.admin_password

  os_disk {
    name                 = "${local.name}-os-disk"
    caching              = "ReadWrite"
    storage_account_type = "StandardSSD_LRS"
  }

  additional_unattend_content {
    setting = "AutoLogon"
    content = "<AutoLogon><Password><Value>${var.admin_password}</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount><Username>${var.admin_username}</Username></AutoLogon>"
  }

  additional_unattend_content {
    setting = "FirstLogonCommands"
    content = file("${path.root}/FirstLogonCommands.xml")
  }
}
bug servicvirtual-machine

Most helpful comment

Hi all,

Any update on this bug. We are experiencing the same bug with azurerm_linux_virtual_machine.
Terraform: 0.13.5
Azurerm: v2.37.0

Thanks.

All 6 comments

Hi, want to know if there is any update on this issue?

Hello, I also have encountered similar error with Terraform 0.12.29 and its blocking the use of Managed disk(with packer imaged) to be deployed. Appreciate if we could prioritize this

Terraform v0.12.29

  • provider.azurerm v2.10.0

Hi all, are there any known work arounds to this issue?

Thanks

This still seems to be an issue with terraform 0.12.26 and azure 2.30

Hi, Also experiencing this issue.

Is this still being worked on?

Hi all,

Any update on this bug. We are experiencing the same bug with azurerm_linux_virtual_machine.
Terraform: 0.13.5
Azurerm: v2.37.0

Thanks.

Was this page helpful?
0 / 5 - 0 ratings