Linter 規則 - 使用穩定資源識別碼
資源名稱不應使用不具決定性的值。 例如,newGuid()
或 utcNow()
無法用於資源名稱;資源名稱不能包含預設值使用 newGuid()
或 utcNow()
的參數/變數。
Linter 規則程式碼
使用 Bicep 設定檔中的下列值來自訂規則設定:
use-stable-resource-identifiers
解決方案
下列範例會在此測試中失敗,因為 utcNow()
用於資源名稱中。
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'
}
}
您可以從範例中移除 utcNow()
函式來修正此問題。
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'
}
}
下一步
如需 Linter 的詳細資訊,請參閱使用 Bicep Linter。