Preserving existing properties during deploymnet
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
I'm frustrated when I am unable to do simple things like add a tag to an existing resource without wiping out pre-existing tags that may have previously been added. Here is an example of an ARM template I need to write when I need a deployment to add a tag and avoid wiping out other tags that might have been manually added for other purposes:
```json
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"dataPlaneSubscriptionRegionsTagDefault": {
"type": "string"
},
"dataPlaneSubscriptionRegionsTagOverride": {
"type": "string"
}
},
"variables": {
},
"resources": [
{
"name": "nestedTagDeployment",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"location": "[deployment().location]",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "Inner"
},
"parameters": {
"dataPlaneSubscriptionRegionsTagOverride": {
"value": "[parameters('dataPlaneSubscriptionRegionsTagOverride')]"
},
"dataPlaneSubscriptionRegionsTagDefault": {
"value": "[parameters('dataPlaneSubscriptionRegionsTagDefault')]"
},
"existingTags": {
"value": "[reference(extensionResourceId(subscription().id, 'Microsoft.Resources/tags', 'default'),'2021-04-01').tags]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"dataPlaneSubscriptionRegionsTagDefault": {
"type": "string"
},
"dataPlaneSubscriptionRegionsTagOverride": {
"type": "string"
},
"existingTags": {
"type": "object"
}
},
"variables": {
"newSubscriptionTags": {
"type": "object",
"value": {
"xyz-service-subscription-purpose": "data-plane-compute",
"xyz-service-subscription-regions": "[if(equals(parameters('dataPlaneSubscriptionRegionsTagOverride'), ''),parameters('dataPlaneSubscriptionRegionsTagDefault'),parameters('dataPlaneSubscriptionRegionsTagOverride'))]"
}
}
},
"resources": [
{
"type": "Microsoft.Resources/tags",
"apiVersion": "2021-04-01",
"name": "default",
"scope": "",
"properties": {
"tags": "[union(parameters('existingTags'), variables('newSubscriptionTags').value)]"
}
}
],
"outputs": {}
}
}
}
]
}
```
The equivalent of this in Bicep is more concise but needs to be spread across two files:
**template.bicep**
```bicep
targetScope = 'subscription'
param dataPlaneSubscriptionRegionsTagDefault string
param dataPlaneSubscriptionRegionsTagOverride string
module nestedTagDeployment './deploy-tags.bicep' = {
name: 'nestedTagDeployment'
params: {
dataPlaneSubscriptionRegionsTagOverride: dataPlaneSubscriptionRegionsTagOverride
dataPlaneSubscriptionRegionsTagDefault: dataPlaneSubscriptionRegionsTagDefault
existingTags: reference(extensionResourceId(subscription().id, 'Microsoft.Resources/tags', 'default'), '2021-04-01').tags
}
}
```
**deploy-tags.bicep**
```bicep
targetScope = 'subscription'
param dataPlaneSubscriptionRegionsTagDefault string
param dataPlaneSubscriptionRegionsTagOverride string
param existingTags object
var newSubscriptionTags = {
type: 'object'
value: {
'xyz-service-subscription-purpose': 'data-plane-compute'
'xyz-service-subscription-regions': ((dataPlaneSubscriptionRegionsTagOverride == '') ? dataPlaneSubscriptionRegionsTagDefault : dataPlaneSubscriptionRegionsTagOverride)
}
}
resource default 'Microsoft.Resources/tags@2021-04-01' = {
name: 'default'
properties: {
tags: union(existingTags, newSubscriptionTags.value)
}
}
```
What I would really like is a much more concise way of saying ... update the resource with the following values but leave everything else the same. This is one of those areas where ARM templates are quite painful to work with and I was hoping that Bicep could take some of the pain away.
Contributor guide
Research direction
Start by comparing the template.bicep and deploy-tags.bicep examples with the equivalent ARM template in the issue. Investigate how Bicep currently models updates to existing resource properties and whether a concise preservation mechanism is feasible. Done means expressing the tag update without a separate nested deployment or manually referencing and merging existing tags.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100