@@ -19,10 +19,10 @@ Function Get-PackerTemplatePath {
1919 switch ($ImageType ) {
2020 # Note: Double Join-Path is required to support PowerShell 5.1
2121 ([ImageType ]::Windows2019) {
22- $relativeTemplatePath = Join-Path (Join-Path " windows" " templates" ) " windows-2019.json "
22+ $relativeTemplatePath = Join-Path (Join-Path " windows" " templates" ) " windows-2019.pkr.hcl "
2323 }
2424 ([ImageType ]::Windows2022) {
25- $relativeTemplatePath = Join-Path (Join-Path " windows" " templates" ) " windows-2022.json "
25+ $relativeTemplatePath = Join-Path (Join-Path " windows" " templates" ) " windows-2022.pkr.hcl "
2626 }
2727 ([ImageType ]::Ubuntu2004) {
2828 $relativeTemplatePath = Join-Path (Join-Path " ubuntu" " templates" ) " ubuntu-20.04.json"
@@ -155,7 +155,7 @@ Function GenerateResourcesAndImage {
155155 if ($Force -and $ReuseResourceGroup ) {
156156 throw " Force and ReuseResourceGroup cannot be used together."
157157 }
158-
158+
159159 Show-LatestCommit - ErrorAction SilentlyContinue
160160
161161 # Validate packer is installed
@@ -229,6 +229,13 @@ Function GenerateResourcesAndImage {
229229
230230 $InstallPassword = $env: UserName + [System.GUID ]::NewGuid().ToString().ToUpper()
231231
232+ Write-Host " Downloading packer plugins..."
233+ & $PackerBinary init $TemplatePath
234+
235+ if ($LastExitCode -ne 0 ) {
236+ throw " Packer plugins download failed."
237+ }
238+
232239 Write-Host " Validating packer template..."
233240 & $PackerBinary validate `
234241 " -var=client_id=fake" `
@@ -242,7 +249,7 @@ Function GenerateResourcesAndImage {
242249 " -var=allowed_inbound_ip_addresses=$ ( $AllowedInboundIpAddresses ) " `
243250 " -var=azure_tags=$ ( $TagsJson ) " `
244251 $TemplatePath
245-
252+
246253 if ($LastExitCode -ne 0 ) {
247254 throw " Packer template validation failed."
248255 }
@@ -290,7 +297,7 @@ Function GenerateResourcesAndImage {
290297 # Resource group already exists, ask the user what to do
291298 $title = " Resource group '$ResourceGroupName ' already exists"
292299 $message = " Do you want to delete the resource group and all resources in it?"
293-
300+
294301 $options = @ (
295302 [System.Management.Automation.Host.ChoiceDescription ]::new(" &Yes" , " Delete the resource group and all resources in it." ),
296303 [System.Management.Automation.Host.ChoiceDescription ]::new(" &No" , " Keep the resource group and continue." ),
@@ -346,7 +353,7 @@ Function GenerateResourcesAndImage {
346353 if ($LastExitCode -ne 0 ) {
347354 throw " Failed to create service principal '$ServicePrincipalName '."
348355 }
349-
356+
350357 $ServicePrincipalAppId = $ServicePrincipal.appId
351358 $ServicePrincipalPassword = $ServicePrincipal.password
352359 $TenantId = $ServicePrincipal.tenant
@@ -383,7 +390,7 @@ Function GenerateResourcesAndImage {
383390 Write-Error $_
384391 } finally {
385392 Write-Verbose " `n Cleaning up..."
386-
393+
387394 # Remove ADServicePrincipal and ADApplication
388395 if ($ADCleanupRequired ) {
389396 Write-Host " Removing ADServicePrincipal..."
0 commit comments