Why is this an issue?

Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.

Exceptions

The following are ignored:

How to fix it in ARM templates

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.

Code examples

Noncompliant code example

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"
      }
    }
  ]
}

Compliant solution

{
  "$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')]"
      }
    }
  ]
}

How to fix it in Bicep

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.

Code examples

Noncompliant code example

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
  }
}

Compliant solution

var storageAccountName = 'appSuperStorage'

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = {
  name: storageAccountName
  tags: {
    displayName: storageAccountName
    shortName: storageAccountName
    someName: storageAccountName
    yetAnotherName: storageAccountName
  }
}

Resources

Documentation

Related rules