I'm trying to pull a Windows 11 image from the Azure marketplace using Packer. Below is the json template I'm using :
{
"builders": [
{
"type": "azure-arm",
"use_azure_cli_auth": true,
"shared_image_gallery_destination": {
"subscription": "",
"resource_group": "",
"gallery_name": "",
"image_name": "",
"image_version": ""
},
"build_resource_group_name": "",
"virtual_network_name": "",
"virtual_network_subnet_name": "",
"virtual_network_resource_group_name": "",
"os_type": "Windows",
"image_publisher": "MicrosoftWindowsDesktop",
"image_offer": "windows-11",
"image_sku": "win11-22h2-avd",
"image_version": "22621.1848.230621",
"azure_tags": {
"assignment_group": ""
},
"vm_size": "Standard_D4d_v5",
"build_key_vault_name": "",
"communicator": "winrm",
"winrm_timeout": "3m",
"winrm_insecure": "true",
"winrm_port": "",
"winrm_no_proxy": "true",
"winrm_use_ssl": "true",
"winrm_use_ntlm": "true"
}
],
"provisioners": [
{
"type": "powershell",
"inline": [
"& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit",
"while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }"
]
}
]
}
Initially an image was created but I was not able to create a VM. I used to receive an error: OS Provisioning for VM 'testVM' did not finish in the allotted time. However, the VM guest agent was detected running. This suggests the guest OS has not been properly prepared to be used as a VM image (with CreateOption=FromImage). I came across a resolution that running sysprep might help resolve this issue. So I have given the command through "inline" but not sure if this is right. Could anyone please help me resolve the same