I'm looking for a working example on how pass dynamic tags to a bicep deployment. I'm currently testing with a single tag, but if I can get it working, will move onto multiple tags per deployment.
Here is the bicep file:
param tagValues object = {}
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
name: 'storage123x01'
location: westeurope
tags: tagValues
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
allowBlobPublicAccess: false
networkAcls: {
defaultAction: 'Deny'
}
}
}
I can change the tagValues param on the bicep template to the following and it works:
param tagValues object = {
commonTag1: 'commonValue1'
}
However, as the the tags are dependent on several factors during deployment, I need a way to dynamically assign when deploying the resource via Azure CLI on AzDO, rather than hardcoding it on the template. This is what my Azdo task looks like (For proof of concept purposes, I'm hardcoding the tag):
- task: AzureCLI@2
displayName: "Create Storage Account"
inputs:
azureSubscription: $(SPN)
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: |
az deployment group create `
--resource-group $(resourceGroup) `
--template-file $(storageAccountTemplate) `
--parameters `
tagValues="commonTag2`:` 'commonValue2'"
I've tried multiple things but I'm can't find any success and pretty much maxed out my knowledge.
Does anyone have any idea on how this can be achieved please?
Thanks.
Thanks for confirming @Clumsyhands ,
Based on this MICROSOFT DOCUMENTATION to add the multiple tags to the storage account/or any resource , For better approach we can specify them into a variable then pass the same in deployment in parameter as shown in below mentioned cli cmdlts
;
$tags="{'Owner':'Contoso','Cost Center':'2345-324'}"
az deployment group create --name addstorage --resource-group myResourceGroup \
--template-file $bicepFile \
--parameters resourceName=abcdef4556 resourceTags=$tags