Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.
The following are ignored:
apiVersion property of a resource (see rule {rule:azureresourcemanager:S6874}) type in nested templates $schema property 1.0.0 or 1-0-0 [[, like [[variables('variableName')] Use variables to replace the duplicated string literals. Variables can be referenced from many places, but only need to be updated in a single place.
With the default threshold of 5:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-01-01",
"name": "appSuperStorage",
"tags": {
"displayName": "appSuperStorage",
"shortName" : "appSuperStorage",
"someName": "appSuperStorage",
"yetAnotherName": "appSuperStorage"
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"storageAccountName": "appSuperStorage"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-01-01",
"name": "[variables('storageAccountName')]",
"tags": {
"displayName": "[variables('storageAccountName')]",
"shortName" : "[variables('storageAccountName')]",
"someName": "[variables('storageAccountName')]",
"yetAnotherName": "[variables('storageAccountName')]"
}
}
]
}
Use variables to replace the duplicated string literals. Variables can be referenced from many places, but only need to be updated in a single place.
With the default threshold of 5:
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = {
name: 'appSuperStorage' // Noncompliant
tags: {
displayName: 'appSuperStorage' // Noncompliant
shortName: 'appSuperStorage' // Noncompliant
someName: 'appSuperStorage' // Noncompliant
yetAnotherName: 'appSuperStorage' // Noncompliant
}
}
var storageAccountName = 'appSuperStorage'
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = {
name: storageAccountName
tags: {
displayName: storageAccountName
shortName: storageAccountName
someName: storageAccountName
yetAnotherName: storageAccountName
}
}