对于表示资源 ID 的所有属性,请确保使用符号资源名称或合适的函数的 ID,而不是手动创建的 ID,例如串联字符串。 尽可能使用资源符号名称。
允许的函数包括:
注释
此规则默认处于关闭状态。 更改 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。