Linter-regel – använd stabil resursidentifierare
Resursnamnet får inte använda ett icke-deterministiskt värde. Till exempel, newGuid()
eller utcNow()
kan inte användas i resursnamn. Resursnamnet får inte innehålla en parameter/variabel vars standardvärde använder newGuid()
eller utcNow()
.
Linterregelkod
Använd följande värde i Bicep-konfigurationsfilen för att anpassa regelinställningar:
use-stable-resource-identifiers
Lösning
Följande exempel misslyckas med det här testet eftersom utcNow()
det används i resursnamnet.
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'
}
}
Du kan åtgärda det genom att ta bort utcNow()
funktionen från exemplet.
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'
}
}
Nästa steg
Mer information om linter finns i Använda Bicep-linter.