I am trying to build a windows machine in azure using packing. Unfortunately one flaky piece of software needs a specific user name (Think Something Like StoreID_1234) so it can be installed. How can I tell Packer to use that user name?
Current packer file:
packer {
required_plugins {
azure = {
source = "github.com/hashicorp/azure"
version = "~> 2"
}
}
}
source "azure-arm" "avd" {
# WinRM Communicator
communicator = "winrm"
winrm_use_ssl = true
winrm_insecure = true
winrm_timeout = "5m"
winrm_username = "packer"
# Service Principal Authentication
# subscription_id = var.subscription_id
# tenant_id = var.tenant_id
use_azure_cli_auth = true
# Source Image
os_type = "Windows"
image_publisher = var.source_image_publisher
image_offer = var.source_image_offer
image_sku = var.source_image_sku
image_version = var.source_image_version
# Destination Image
managed_image_resource_group_name = var.artifacts_resource_group
managed_image_name = "${var.source_image_sku}-${var.source_image_version}"
# Packer Computing Resources
build_resource_group_name = var.build_resource_group
vm_size = "Standard_DS3_v2"
}
build {
source "azure-arm.avd" {}
# Install Chocolatey: https://chocolatey.org/install#individual
provisioner "powershell" {
inline = ["Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"]
}
# Install Chocolatey packages
provisioner "file" {
source = "./packages.config"
destination = "D:/packages.config"
}
provisioner "powershell" {
inline = ["choco install --confirm D:/packages.config"]
# See https://docs.chocolatey.org/en-us/choco/commands/install#exit-codes
valid_exit_codes = [0, 3010]
}
provisioner "windows-restart" {}
# Azure PowerShell Modules
provisioner "powershell" {
script = "./install-azure-powershell.ps1"
}
# Generalize image using Sysprep
# See https://www.packer.io/docs/builders/azure/arm#windows
# See https://docs.microsoft.com/en-us/azure/virtual-machines/windows/build-image-with-packer#define-packer-template
provisioner "powershell" {
inline = [
"while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }",
"while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }",
"& $env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit /mode:vm",
"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 } }"
]
}
}
1