確定會針對代表資源標識碼的所有屬性使用符號資源名稱或適當的函式識別碼,而不是手動建立的標識符,例如串連字串。 盡可能使用資源符號名稱。
允許函式包括:
備註
此規則預設為關閉。 變更 bicepconfig.json 中的層級以啟用。
Linter 規則程式碼
使用 Bicep 設定檔中的下列值來自訂規則設定:
use-resource-id-functions
解決方法
下列範例會失敗此測試,因為資源的 api/id 屬性會使用手動建立的字串:
@description('description')
param connections_azuremonitorlogs_name string
@description('description')
param location string
@description('description')
param resourceTags object
param tenantId string
resource connections_azuremonitorlogs_name_resource 'Microsoft.Web/connections@2016-06-01' = {
name: connections_azuremonitorlogs_name
location: location
tags: resourceTags
properties: {
displayName: 'azuremonitorlogs'
statuses: [
{
status: 'Connected'
}
]
nonSecretParameterValues: {
'token:TenantId': tenantId
'token:grantType': 'code'
}
api: {
name: connections_azuremonitorlogs_name
displayName: 'Azure Monitor Logs'
description: 'Use this connector to query your Azure Monitor Logs across Log Analytics workspace and Application Insights component, to list or visualize results.'
iconUri: 'https://connectoricons-prod.azureedge.net/releases/v1.0.1501/1.0.1501.2507/${connections_azuremonitorlogs_name}/icon.png'
brandColor: '#0072C6'
id: '/subscriptions/<subscription_id_here>/providers/Microsoft.Web/locations/<region_here>/managedApis/${connections_azuremonitorlogs_name}'
type: 'Microsoft.Web/locations/managedApis'
}
}
}
您可以使用 函 subscriptionResourceId() 式來修正此問題:
@description('description')
param connections_azuremonitorlogs_name string
@description('description')
param location string
@description('description')
param resourceTags object
param tenantId string
resource connections_azuremonitorlogs_name_resource 'Microsoft.Web/connections@2016-06-01' = {
name: connections_azuremonitorlogs_name
location: location
tags: resourceTags
properties: {
displayName: 'azuremonitorlogs'
statuses: [
{
status: 'Connected'
}
]
nonSecretParameterValues: {
'token:TenantId': tenantId
'token:grantType': 'code'
}
api: {
name: connections_azuremonitorlogs_name
displayName: 'Azure Monitor Logs'
description: 'Use this connector to query your Azure Monitor Logs across Log Analytics workspace and Application Insights component, to list or visualize results.'
iconUri: 'https://connectoricons-prod.azureedge.net/releases/v1.0.1501/1.0.1501.2507/${connections_azuremonitorlogs_name}/icon.png'
brandColor: '#0072C6'
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', location, connections_azuremonitorlogs_name)
type: 'Microsoft.Web/locations/managedApis'
}
}
}
後續步驟
如需 Linter 的詳細資訊,請參閱使用 Bicep Linter。