hashicorp / hashicorp/packer-plugin-azure
Azure plugin 2.5.1: sysprepping not returning and packer hanging + powershell scripts not streaming
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 63
- Forks
- 103
- PR merge metrics
- No merged PRs in 30d
Description
Overview of the Issue
Issues present in 2.5.1 and not in 2.5.0.
Issues:
- the powershell provisioner which runs my sysprep script won't return and packer hangs indefinitely (while run from Azure pipeline)
- the powershell provisioner running other scripts won't stream the output, but just dump the output at the end of the script
Reproduction Steps
Try and create a Windows 11 (e.g. microsoftwindowsdesktop:windows-11:win11-24h2-avd) with the azure plugin 2.5.1. In the packer configuration add scripts that output with "Write-Output". Outputs are not streamed but are dumped at the end of the script.
More problematic is when a sysprep script is run with the powershell provisioner, the script will effectively run the sysprep, but packer will end without returning from the call.
Plugin and Packer version
Packer and its plugins are distinct binaries.
Packer version: "1.14.1"
Azure plugin: "2.5.1"
Simplified Packer Buildfile
packer {
required_plugins {
azure = {
source = "github.com/hashicorp/azure"
version = "2.5.1"
}
}
}
source "azure-arm" "golden-image" {
use_azure_cli_auth = true
communicator = "winrm"
winrm_username = local.admin_username
winrm_timeout = "5m"
winrm_insecure = true
winrm_use_ssl = true
image_offer = var.image_offer
image_publisher = var.image_publisher
image_sku = var.image_sku
location = "uksouth"
os_type = "Windows"
os_disk_size_gb = var.config.images_settings[var.image_name].os_disk_size_gb
vm_size = "Standard_B4ms"
user_assigned_managed_identities = [var.config.user_assigned_managed_identity_id]
virtual_network_name = var.config.virtual_network_name
virtual_network_subnet_name = var.config.virtual_network_subnet_name
virtual_network_resource_group_name = var.config.virtual_network_resource_group_name
private_virtual_network_with_public_ip = var.config.private_virtual_network_with_public_ip
shared_image_gallery_destination {
subscription = var.gallery_subscription_id
resource_group = var.gallery_resource_group
gallery_name = var.gallery_name
image_name = var.image_name
image_version = var.image_version
storage_account_type = "Standard_LRS"
target_region {
name = "uksouth"
}
}
build {
sources = ["source.azure-arm.golden-image"]
# Install all tools
provisioner "powershell" {
environment_vars = [
# truncated
]
scripts = concat(
local.core_image_scripts,
local.image_specific_scripts
)
timeout = var.config.install_tools_timeout
}
provisioner "windows-restart" {
pause_before = "120s"
restart_check_command = "powershell -command \"& {Write-Output 'Machine restarted.'}\""
restart_timeout = "60m"
}
# other provisioners truncated
# sysprepping
provisioner "powershell" {
environment_vars = [
"RUN_FROM_PACKER=true"
]
scripts = [
"${path.root}/../../scripts/prepare-windows-vm.ps1"
]
elevated_user = local.admin_username
elevated_password = build.Password
}
Operating system and Environment details
Runner: linux image on an Azure Managed DevOps Pool
Log Fragments and crash.log files
After 12 hours of running, the pipeline gets cancelled and the last few lines of the output is:
==> azure-arm.golden-image: Provisioning with Powershell...
==> azure-arm.golden-image: Provisioning with powershell script: /mnt/vss/_work/1/src/image-builder/core-components/../../scripts/prepare-windows-vm.ps1
##[error]The Operation will be canceled. The next steps may not contain expected logs.
##[error]The operation was canceled.
The prepare-windows-vm.ps1 runs successfully (I can see the sysprep logs from the azure VM itself), but packer won't continue further.
Expected next steps: saving the image to the gallery.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the powershell provisioner and the referenced scripts/prepare-windows-vm.ps1, reproducing the simplified Azure build on Windows 11 with Write-Output and sysprep. Compare behavior between Azure plugin 2.5.0 and 2.5.1. Done means script output streams during execution, sysprep returns to Packer, and the build proceeds to saving the image to the gallery.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, go, powershell
- Domain
- cloud, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100