diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index 5b3c83842..f6fe10adf 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -268,14 +268,19 @@ Function GenerateResourcesAndImage { } else { $AgentIp = "[]" } + if (-not $Tags) { + $Tags = @{} + } } - 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 | ConvertTo-Json -Depth 3 | Out-File $builderScriptPath_temp - $builderScriptPath = $builderScriptPath_temp + if ($builderScriptPath.Contains(".json")) { + 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 | ConvertTo-Json -Depth 3 | Out-File $builderScriptPath_temp + $builderScriptPath = $builderScriptPath_temp + } } & $packerBinary build -on-error="$($OnError)" ` @@ -288,6 +293,7 @@ Function GenerateResourcesAndImage { -var "storage_account=$($storageAccountName)" ` -var "install_password=$($InstallPassword)" ` -var "allowed_inbound_ip_addresses=$($AgentIp)" ` + -var "azure_tags=$($Tags | ConvertTo-Json -Compress)" ` $builderScriptPath } catch { diff --git a/images/linux/ubuntu2204.pkr.hcl b/images/linux/ubuntu2204.pkr.hcl index 9b6e0851a..7a718eb60 100644 --- a/images/linux/ubuntu2204.pkr.hcl +++ b/images/linux/ubuntu2204.pkr.hcl @@ -4,7 +4,7 @@ variable "allowed_inbound_ip_addresses" { default = [] } -variable "azure_tag" { +variable "azure_tags" { type = map(string) default = {} } @@ -171,7 +171,7 @@ source "azure-arm" "build_vhd" { vm_size = "${var.vm_size}" dynamic "azure_tag" { - for_each = var.azure_tag + for_each = var.azure_tags content { name = azure_tag.key value = azure_tag.value