Repository: hashicorp/terraform-provider-azurerm

Issue #7772: azurerm_windows_virtual_machine fails to create when referencing a "specialised" shared gallery image.
Created: 2020-07-16T02:21:13Z
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


Terraform (and AzureRM Provider) Version
Terraform v0.12.28
+ provider.azuread v0.10.0
+ provider.azurerm v2.18.0

Affected Resource(s)


azurerm_windows_virtual_machine

Terraform Configuration Files

resource "azurerm_windows_virtual_machine" "pool" {
  for_each = {
    for key, i in local.vm_config :
    key => i
  }
  
  name                  = each.value.vm_name
  resource_group_name   = var.resource_group_name
  location              = var.location
  size                  = each.value.vm_size
  admin_username        = each.value.admin_username
  admin_password        = each.value.admin_password
  network_interface_ids = each.value.network_interface_ids
  license_type          = each.value.license_type
  timezone              = each.value.timezone
  
  source_image_id       = each.value.source_image_id
 #redacted source_image_id value: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rgvmimagedemo/providers/Microsoft.Compute/galleries/myGallary/images/windows_server_2019/versions/0.0.1
  
  tags                  = merge(var.tags, { purpose = each.value.purpose }, { node = each.value.node_key + 1 })
  
  os_disk {
    caching              = each.value.os_disk_caching
    storage_account_type = each.value.os_disk_storage_account_type
  }

  # source_image_reference {
  #   publisher = "MicrosoftWindowsServer"
  #   offer     = "WindowsServer"
  #   sku       = "2019-Datacenter"
  #   version   = "latest"
  # }

Debug Output

Panic Output

Expected Behavior
Deploy two Windows VMs from "Shared Gallery Image"
Actual Behavior
A spurious error that does not relate to the issue.
module.compute_region_0.module.windows_virtual_machine.azurerm_windows_virtual_machine.pool["1"]: Creating...
Error: creating Windows Virtual Machine "vm1" (Resource Group "rgvmimagedemo"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"

  on ..\azurerm_windows_virtual_machine\main.tf line 82, in resource "azurerm_windows_virtual_machine" "pool":
  82: resource "azurerm_windows_virtual_machine" "pool" {

Repeats for VM2.
(Line 82 is the begining of the resource: resource "azurerm_windows_virtual_mahine" "pool" {)
If this isn't a bug, please consider updating the document that would resolve my mistake. Perhaps an example of using source_image_id.
Steps to Reproduce


terraform apply

Important Factoids
This may be related to #5998 although the error is different.
Plan succeeds.
I did a test by creating the old os_profile{} block, adding admin_username and admin_password which made the plan fail.
If this is the same regression as mentioned in #5998, can you check azurerm_linux_virtual_machine too, please?
If I comment out source_image_id and use source_image_reference instead, apply works and the VMs deploy.
T. I. A.
References

There is an unanswered related question on your discuss site: https://discuss.hashicorp.com/t/unable-to-create-azure-windows-vm/6672

#5998

Duplicate issue #9637: azurerm_windows_virtual_machine_scale_set fails when using a specialized image
Created: 2020-12-03T01:57:47Z
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


Terraform (and AzureRM Provider) Version
Terraform v0.13.5

provider registry.terraform.io/hashicorp/aws v3.19.0
provider registry.terraform.io/hashicorp/azuread v1.1.1
provider registry.terraform.io/hashicorp/azurerm v2.38.0

Affected Resource(s)

azurerm_windows_virtual_machine_scale_set
azurerm_shared_image_version

Terraform Configuration Files
data "azurerm_shared_image" "pipeline_autoscale_image_ocr_dev2" {
  name                = "autoscaling-image-ocr-dev"
  gallery_name        = data.azurerm_shared_image_gallery.autoscaling_images.name
  resource_group_name = data.azurerm_shared_image_gallery.autoscaling_images.resource_group_name
}

data "azurerm_shared_image_version" "pipeline_autoscale_image_ocr_dev2_v1" {
  name                = "1.0.0"
  image_name          = data.azurerm_shared_image.pipeline_autoscale_image_ocr_dev2.name
  gallery_name        = data.azurerm_shared_image_gallery.autoscaling_images.name
  resource_group_name = data.azurerm_shared_image_gallery.autoscaling_images.resource_group_name
}

resource "azurerm_windows_virtual_machine_scale_set" "pipeline_dev2_text_win_autoscale_schedule" {

  name                = "pipetextwindev2schedule"
  location            = data.azurerm_resource_group.dev2.location
  resource_group_name = data.azurerm_resource_group.dev2.name

  sku = "Standard_F4s_v2"
  upgrade_mode = "Manual"
  instances = 0
  overprovision = false
  source_image_id = data.azurerm_shared_image_version.pipeline_autoscale_image_ocr_dev2_v1.id

  os_disk {
    caching = "ReadWrite"
    storage_account_type = "StandardSSD_LRS"
  }

  # since the underlying image we're using is a specialized image, I would expect these to be ignored
  computer_name_prefix = "textsched"
  admin_username = "somethingadminlike"
  admin_password = "completelyignoredandunused"

  network_interface {
    name    = "pipetextdev2-networkprofile"
    primary = true
    network_security_group_id = azurerm_network_security_group.pipeline_pipelinetier_dev2.id
    ip_configuration {
      name         = "pipetextdev2-ipconfig"
      subnet_id    = "${data.azurerm_virtual_network.dev2_vnet.id}/subnets/${data.azurerm_subnet.dev2_subnet_default.name}"
      primary      = true
      public_ip_address {
        name                    = "pipetextdev2-publicipconfig"
        domain_name_label       = "textwinsched"
        idle_timeout_in_minutes = 15
      }
    }
  }

  identity {
    type = "SystemAssigned"
  }

  lifecycle {
    ignore_changes = [ instances, automatic_os_upgrade_policy ]
  }
}
Expected Behaviour
I expected terraform to create the VMSS
Actual Behaviour
azurerm_windows_virtual_machine_scale_set.pipeline_dev2_text_win_autoscale_schedule: Creating...
Error: Error creating Windows Virtual Machine Scale Set "pipetextwindev2schedule" (Resource Group "dev2"): compute.VirtualMachineScaleSetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"
on autoscaling_vidprocessor_text.tf line 105, in resource "azurerm_windows_virtual_machine_scale_set" "pipeline_dev2_text_win_autoscale_schedule":
105: resource "azurerm_windows_virtual_machine_scale_set" "pipeline_dev2_text_win_autoscale_schedule" {

Closing comment (2021-03-16T07:31:07Z): Duplicate of #7772, thanks for the cross-link @AliAllomani