Fix failure when tags are set for Ubuntu 22 generation (#7417)

This commit is contained in:
Vasilii Polikarpov
2023-04-12 14:32:59 +02:00
committed by GitHub
parent f01bed49d5
commit 3220eb4c1b
2 changed files with 14 additions and 8 deletions

View File

@@ -268,8 +268,12 @@ Function GenerateResourcesAndImage {
} else { } else {
$AgentIp = "[]" $AgentIp = "[]"
} }
if (-not $Tags) {
$Tags = @{}
}
} }
if ($builderScriptPath.Contains(".json")) {
if ($Tags) { if ($Tags) {
$builderScriptPath_temp = $builderScriptPath.Replace(".json", "-temp.json") $builderScriptPath_temp = $builderScriptPath.Replace(".json", "-temp.json")
$packer_script = Get-Content -Path $builderScriptPath | ConvertFrom-Json $packer_script = Get-Content -Path $builderScriptPath | ConvertFrom-Json
@@ -277,6 +281,7 @@ Function GenerateResourcesAndImage {
$packer_script | ConvertTo-Json -Depth 3 | Out-File $builderScriptPath_temp $packer_script | ConvertTo-Json -Depth 3 | Out-File $builderScriptPath_temp
$builderScriptPath = $builderScriptPath_temp $builderScriptPath = $builderScriptPath_temp
} }
}
& $packerBinary build -on-error="$($OnError)" ` & $packerBinary build -on-error="$($OnError)" `
-var "client_id=$($spClientId)" ` -var "client_id=$($spClientId)" `
@@ -288,6 +293,7 @@ Function GenerateResourcesAndImage {
-var "storage_account=$($storageAccountName)" ` -var "storage_account=$($storageAccountName)" `
-var "install_password=$($InstallPassword)" ` -var "install_password=$($InstallPassword)" `
-var "allowed_inbound_ip_addresses=$($AgentIp)" ` -var "allowed_inbound_ip_addresses=$($AgentIp)" `
-var "azure_tags=$($Tags | ConvertTo-Json -Compress)" `
$builderScriptPath $builderScriptPath
} }
catch { catch {

View File

@@ -4,7 +4,7 @@ variable "allowed_inbound_ip_addresses" {
default = [] default = []
} }
variable "azure_tag" { variable "azure_tags" {
type = map(string) type = map(string)
default = {} default = {}
} }
@@ -171,7 +171,7 @@ source "azure-arm" "build_vhd" {
vm_size = "${var.vm_size}" vm_size = "${var.vm_size}"
dynamic "azure_tag" { dynamic "azure_tag" {
for_each = var.azure_tag for_each = var.azure_tags
content { content {
name = azure_tag.key name = azure_tag.key
value = azure_tag.value value = azure_tag.value