From c3fb682f73f0baff6423bdc59d92fe36563eb18e Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov <47745270+al-cheb@users.noreply.github.com> Date: Tue, 24 May 2022 13:30:13 +0200 Subject: [PATCH] [ImageGen] Fix allowed_inbound_ip_addresses error (#5597) * Fix allowed_inbound_ip_addresses error * Add space --- helpers/GenerateResourcesAndImage.ps1 | 12 ++++++++---- images/linux/ubuntu2204.pkr.hcl | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index e62dd4ad..6a7f864d 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -119,7 +119,7 @@ Function GenerateResourcesAndImage { [Parameter(Mandatory = $False)] [bool] $EnableHttpsTrafficOnly = $False, [Parameter(Mandatory = $False)] - [Hashtable] $tags + [hashtable] $Tags ) try { @@ -260,15 +260,19 @@ Function GenerateResourcesAndImage { throw "'packer' binary is not found on PATH" } - if($RestrictToAgentIpAddress -eq $true) { + if ($RestrictToAgentIpAddress) { $AgentIp = (Invoke-RestMethod http://ipinfo.io/json).ip Write-Host "Restricting access to packer generated VM to agent IP Address: $AgentIp" } - if ($tags) { + if ($builderScriptPath.Contains("pkr.hcl")) { + $AgentIp = '[ \"{0}\" ]' -f $AgentIp + } + + if ($Tags) { $builderScriptPath_temp = $builderScriptPath.Replace(".json", "-temp.json") $packer_script = Get-Content -Path $builderScriptPath | ConvertFrom-Json - $packer_script.builders | Add-Member -Name "azure_tags" -Value $tags -MemberType NoteProperty + $packer_script.builders | Add-Member -Name "azure_tags" -Value $Tags -MemberType NoteProperty $packer_script | ConvertTo-Json -Depth 3 | Out-File $builderScriptPath_temp $builderScriptPath = $builderScriptPath_temp } diff --git a/images/linux/ubuntu2204.pkr.hcl b/images/linux/ubuntu2204.pkr.hcl index 7c50638e..b82227ec 100644 --- a/images/linux/ubuntu2204.pkr.hcl +++ b/images/linux/ubuntu2204.pkr.hcl @@ -1,5 +1,6 @@ variable "allowed_inbound_ip_addresses" { + type = list(string) default = [] }