terraform-provider-azurerm: azurerm_windows_virtual_machine fails to create when referencing a "specialised" shared gallery image.
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
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 36
- Comments: 18 (4 by maintainers)
FWIW, I was able to get a specialised image working with the
azurerm_virtual_machineresource type (as mentioned by both @burnedikt and @ChrisPetr0 above), but ONLY when using a base VM that used a “Standard” security type (as opposed to “Trusted Launch” security type, which is becoming the norm). I believe Gen 1 VMs always use Standard security, and Gen 2 VMs usually use Trusted Launch security by default (the Azure CLI will be updated in November).To prove this out, it is possible to force deployment of a Windows 11 Gen 2 Standard Security VM as a base image using the Azure CLI on which we can customise and specialise, for example:
Then, I modify and capture a specialised image in the Azure Compute Gallery. I can then use something like this Terraform to deploy a working VM from this specialised image:
If we do the same process but instead deploy a Windows 11 Gen 2 VM with Trusted Launch security, then customise and capture the specialised image to the Azure Compute Gallery, subsequent VMs fail to deploy from the image. Essentially, the only thing that changes in the Terraform snippet above is the reference to the
storage_image_reference. The error thrown is something like this:I do not believe the
azurerm_virtual_machineresource type supports (or will ever support) the “Trusted Launch” security options, hence our failure.It seems you cannot change the VM security type once it has been deployed, so instead, you would need to start from scratch using this method. Capturing an image of a VM retains the security type. Of course (and as pointed out), the
azurerm_virtual_machineresource type is now deprecated, and the Trusted Launch security type will only ever become more widespread, so you are potentially painting yourself into a corner.When generalising a Gen 2 VM that uses the Trusted Launch security type, I can use some Terraform similar to:
This uses the newer
azurerm_windows_virtual_machineresource type, and we can specify thesecure_boot_enabledandvtpm_enabledparameters to signify a Trusted Launch security VM (although these settings are independent within Azure - you can have a Trusted Launch VM without either Secure Boot or TPM enabled).However, when switching to use a specialised image in the same Terraform snippet, we get another failure:
This is, of course, what @woter1832 initially reported above.
When deploying a VM from a specialised image in the portal, the Admin username and password fields are greyed out. However, we can’t remove the
admin_usernameandadmin_passwordparameters from the Terraform as they are a requirement by theazurerm_windows_virtual_machineresource type. I’m unsure if this is the cause of the issue in this case. Maybe it’s trying to change something in the OS profile that cannot be changed (hence the error).Whatever, this is super frustrating as Gen 2 VMs using the Trusted Launch security type can be deployed from specialised images via the Azure portal and all other Azure command line options.
this issue seems last more than 2 years, no final solution until now, is there any workaround , thanks in advance
Hi, Is there any news on this? I ran into this issue today while trying to create VMs using some internal custom images.