Matthias Wirth
Matthias Wirth

Reputation: 277

Bicep: How to concat tags

I am using a Bicep script to create resources in Mcirosoft Azure.

I have defined a variable with the common tags that are the same for all resources.But now, when assigning this variable to a resource, I want to add more tags that are only for this resource.

However, I have not yet found a way to do this.

Upvotes: 4

Views: 4510

Answers (1)

Thomas
Thomas

Reputation: 29522

You can use the union function to merge object.

In this sample, I've defined a parameter with the common tags and merge the object with resource specific tags:

param commonTags object = {
  commonTag1: 'commonTag1'
  commonTag2: 'commonTag2'
}

resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
  name: 'my storage account name'
  ...
  tags: union(commonTags, {
    storageTag1: 'storageTag1'
    storageTag2: 'storageTag2'
  })
}

Upvotes: 7

Related Questions