I have multiple azure resources that I need to tag during deployment and for which I have bicep files that take the tags as a parameter. All the tags will be the same and with the same value for all the resources, except one tag Type
that will have different values based on the type of resource is being deployed.
param tags object = {}
resource myResourceWithTags 'resourceType' = {
tags: tags
}
Is there a way to pass the tags from the pipeline as { "Type" : "{{type}}" }
and then replace {{type}}
inside the resource with the correct value?
The reason not to do it in the pipeline is because I'm deploying many resources at once and this would require me to have individual tag variables for each resource that will all be essentially the same. The current approach would allow me to define the variable once and let the template handle the update.
I'm thinking something like
tags: contains(tags, 'Type') ? json(replace(tags), '{{type}}', 'appInsights') : tags
But I haven't figured out a way to convert the tags object to a string and back (or a totally better approach).
You could override the Type value using the union
function:
param tags object = {}
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
...
tags: contains(tags, 'Type') ? union(tags, {
Type: 'appInsights'
}) : tags
...
}
You would just need to have a Type property defined with empty value:
{ "Type" : "" }