Regla linter: usar referencia de símbolo del recurso
Esta regla detecta usos poco óptimos de las funciones reference
y list
. En lugar de invocar estas funciones, el uso de una referencia de recursos simplifica la sintaxis y permite a Bicep comprender mejor el gráfico de dependencias de implementación.
Código de regla de linter
Use el valor siguiente del archivo de configuración de Bicep para personalizar los valores de regla:
use-resource-symbol-reference
Solución
En el ejemplo siguiente se produce un error en esta prueba debido a los usos de reference
y listKey
:
@description('The name of the HDInsight cluster to create.')
param clusterName string
@description('These credentials can be used to submit jobs to the cluster and to log into cluster dashboards.')
param clusterLoginUserName string
@description('The password must be at least 10 characters in length and must contain at least one digit, one upper case letter, one lower case letter, and one non-alphanumeric character except (single-quote, double-quote, backslash, right-bracket, full-stop). Also, the password must not contain 3 consecutive characters from the cluster username or SSH username.')
@minLength(10)
@secure()
param clusterLoginPassword string
@description('Location for all resources.')
param location string = resourceGroup().location
param storageAccountName string = uniqueString(resourceGroup().id)
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-04-01' existing = {
name: storageAccountName
}
resource cluster 'Microsoft.HDInsight/clusters@2023-08-15-preview' = {
name: clusterName
location: location
properties: {
clusterVersion: '4.0'
osType: 'Linux'
clusterDefinition: {
kind: 'hbase'
configurations: {
gateway: {
'restAuthCredential.isEnabled': true
'restAuthCredential.username': clusterLoginUserName
'restAuthCredential.password': clusterLoginPassword
}
}
}
storageProfile: {
storageaccounts: [
{
name: replace(replace(reference(storageAccount.id, '2023-04-01').primaryEndpoints.blob, 'https://', ''), '/', '')
isDefault: true
container: clusterName
key: listKeys(storageAccount.id, '2023-04-01').keys[0].value
}
]
}
}
}
Puede corregir el problema mediante las referencias de recursos:
@description('The name of the HDInsight cluster to create.')
param clusterName string
@description('These credentials can be used to submit jobs to the cluster and to log into cluster dashboards.')
param clusterLoginUserName string
@description('The password must be at least 10 characters in length and must contain at least one digit, one upper case letter, one lower case letter, and one non-alphanumeric character except (single-quote, double-quote, backslash, right-bracket, full-stop). Also, the password must not contain 3 consecutive characters from the cluster username or SSH username.')
@minLength(10)
@secure()
param clusterLoginPassword string
@description('Location for all resources.')
param location string = resourceGroup().location
param storageAccountName string = uniqueString(resourceGroup().id)
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-04-01' existing = {
name: storageAccountName
}
resource cluster 'Microsoft.HDInsight/clusters@2023-08-15-preview' = {
name: clusterName
location: location
properties: {
clusterVersion: '4.0'
osType: 'Linux'
clusterDefinition: {
kind: 'hbase'
configurations: {
gateway: {
'restAuthCredential.isEnabled': true
'restAuthCredential.username': clusterLoginUserName
'restAuthCredential.password': clusterLoginPassword
}
}
}
storageProfile: {
storageaccounts: [
{
name: replace(replace(storageAccount.properties.primaryEndpoints.blob, 'https://', ''), '/', '')
isDefault: true
container: clusterName
key: storageAccount.listKeys().keys[0].value
}
]
}
}
}
Para corregir el problema automáticamente, seleccione Corrección rápida, como se muestra en la captura de pantalla siguiente:
Pasos siguientes
Para obtener más información acerca de linter, consulte Uso de linter de Bicep.