From 7e295782c310c31cdb116e80c87a88b78c6da652 Mon Sep 17 00:00:00 2001 From: Shamil Mubarakshin <127750046+shamil-mubarakshin@users.noreply.github.com> Date: Thu, 18 May 2023 07:26:10 +0000 Subject: [PATCH] Add double quote escaping and update documentation (#7613) --- docs/create-image-and-azure-resources.md | 7 ++++++- helpers/GenerateResourcesAndImage.ps1 | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/create-image-and-azure-resources.md b/docs/create-image-and-azure-resources.md index 0e94f64df..6f340b6a6 100644 --- a/docs/create-image-and-azure-resources.md +++ b/docs/create-image-and-azure-resources.md @@ -57,7 +57,7 @@ In any case you will need these software installed: ``` - [Az Powershell module](https://docs.microsoft.com/en-us/powershell/azure/install-az-ps). - + Run this command in Powershell: ```powershell @@ -92,6 +92,11 @@ Finally, run `GenerateResourcesAndImage` function setting mandatory arguments: i - `AzureLocation` - location where resources will be created (e.g. "East US") - `ImageType` - what image to build (we suggest choosing "UbuntuMinimal" here, other valid options are "Windows2019", "Windows2022", "Ubuntu2004", "Ubuntu2204") +> :warning: When running `GenerateResourcesAndImage` in PowerShell 7.3, following command should be executed first: +> ```powershell +> $PSNativeCommandArgumentPassing = 'Legacy' +> ``` + This function automatically creates all required Azure resources and kicks off packer image generation for the selected image type. When image is ready you may proceed to [deployment](#generated-machine-deployment) diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index df6ca77eb..6bd81896b 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -190,8 +190,8 @@ Function GenerateResourcesAndImage { # Resource group names may contain special characters, that are not allowed in the storage account name $storageAccountName = $storageAccountName.Replace("-", "").Replace("_", "").Replace("(", "").Replace(")", "").ToLower() $storageAccountName += "001" - - + + # Storage Account Name can only be 24 characters long if ($storageAccountName.Length -gt 24){ $storageAccountName = $storageAccountName.Substring(0, 24) @@ -266,10 +266,10 @@ Function GenerateResourcesAndImage { $AgentIp = (Invoke-RestMethod http://ipinfo.io/json).ip Write-Host "Restricting access to packer generated VM to agent IP Address: $AgentIp" } - + if ($builderScriptPath.Contains("pkr.hcl")) { if ($AgentIp) { - $AgentIp = '[ "{0}" ]' -f $AgentIp + $AgentIp = '[ \"{0}\" ]' -f $AgentIp } else { $AgentIp = "[]" }