Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New parameter 'AzureTags' in build-image.ps1 #10884

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion images.CI/linux-and-win/build-image.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ param(
[String] [Parameter (Mandatory=$false)] $VirtualNetworkName,
[String] [Parameter (Mandatory=$false)] $VirtualNetworkRG,
[String] [Parameter (Mandatory=$false)] $VirtualNetworkSubnet,
[String] [Parameter (Mandatory=$false)] $AllowedInboundIpAddresses = "[]"
[String] [Parameter (Mandatory=$false)] $AllowedInboundIpAddresses = "[]",
[hashtable] [Parameter(Mandatory = $false)] $AzureTags = @{}
)

if (-not (Test-Path $TemplatePath))
Expand All @@ -33,6 +34,23 @@ $SensitiveData = @(
': ->'
)

#Region Prepare optional Azure tags
$AzureTags.GetEnumerator() | ForEach-Object { Write-Debug "Azure tag: '$($_.Key)' = '$($_.Value)'" }
$AzureTagsJson = $AzureTags | ConvertTo-Json -Compress

# Replace double quotes with escaped double quotes in JSON for PowerShell 5 and 7.0-7.2
# Kudo to authors of 'helpers/GenerateResourcesAndImage.ps1'.
if ($PSVersionTable.PSVersion.Major -eq 5) {
Write-Verbose "PowerShell 5 detected. Replacing double quotes with escaped double quotes in tags JSON."
$AzureTagsJson = $AzureTagsJson -replace '"', '\"'
}
elseif ($PSVersionTable.PSVersion.Major -eq 7 -and $PSVersionTable.PSVersion.Minor -le 2) {
Write-Verbose "PowerShell 7.0-7.2 detected. Replacing double quotes with escaped double quotes in tags JSON."
$AzureTagsJson = $AzureTagsJson -replace '"', '\"'
}
Write-Debug "Azure tags JSON: $AzureTagsJson."
#EndRegion Prepare optional Azure tags

Write-Host "Show Packer Version"
packer --version

Expand All @@ -56,6 +74,7 @@ packer build -var "client_id=$ClientId" `
-var "virtual_network_resource_group_name=$VirtualNetworkRG" `
-var "virtual_network_subnet_name=$VirtualNetworkSubnet" `
-var "allowed_inbound_ip_addresses=$($AllowedInboundIpAddresses)" `
-var "azure_tags=$($AzureTagsJson)" `
-color=false `
$TemplatePath `
| Where-Object {
Expand Down