YannickRe / azuredevops-buildagents

Generate self-hosted build agents for Azure DevOps, just like Microsoft does.
MIT License
153 stars 90 forks source link

passing value for azure_tags paramter #50

Closed RobBowman closed 1 year ago

RobBowman commented 1 year ago

I guess this is likely my lack of knowledge that's causing the problem.

Azure policy on the subscription insists on tags being used.

I've changed build-image.ps1 so that the "azure-tags" parameter is passed as follows:

$azureTags = @{
    BusinessUnit = "IDS"
    Environment  = "Production"
}
packer build    -var "capture_name_prefix=$ResourcesNamePrefix" `
                -var "client_id=$ClientId" `
                -var "client_secret=$ClientSecret" `
                -var "install_password=$InstallPassword" `
                -var "location=$Location" `
                -var "resource_group=$ResourceGroup" `
                -var "storage_account=$StorageAccount" `
                -var "subscription_id=$SubscriptionId" `
                -var "temp_resource_group_name=$TempResourceGroupName" `
                -var "tenant_id=$TenantId" `
                -var "virtual_network_name=$VirtualNetworkName" `
                -var "virtual_network_resource_group_name=$VirtualNetworkRG" `
                -var "virtual_network_subnet_name=$VirtualNetworkSubnet" `
                -var "run_validation_diskspace=$env:RUN_VALIDATION_FLAG" `
                -var "azure_tags=$($azureTags | ConvertTo-Json -Compress)" `

The DevOps pipeline then fails on the BuildVM stage with the following error:

Build ubuntu2204 VM Error: Variables not allowed on value for var.azure_tags from arguments line 1:

Can anyone see what I've got wrong?

RobBowman commented 1 year ago

I received an answer from Paolo on Stack Overflow