Muokkaa

Jaa


Linter rule - use stable resource identifier

Resource name shouldn't use a non-deterministic value. For example, newGuid() or utcNow() can't be used in resource name; resource name can't contain a parameter/variable whose default value uses newGuid() or utcNow().

Linter rule code

Use the following value in the Bicep configuration file to customize rule settings:

use-stable-resource-identifiers

Solution

The following example fails this test because utcNow() is used in the resource name.

param location string = resourceGroup().location
param time string = utcNow()

resource sa 'Microsoft.Storage/storageAccounts@2023-04-01' = {
  name: 'store${toLower(time)}'
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'
  }
}

You can fix it by removing the utcNow() function from the example.

param location string = resourceGroup().location

resource sa 'Microsoft.Storage/storageAccounts@2023-04-01' = {
  name: 'store${uniqueString(resourceGroup().id)}'
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'
  }
}

Next steps

For more information about the linter, see Use Bicep linter.