Regola Linter - Usare il riferimento al simbolo di risorsa
Questa regola rileva usi non ottimali delle reference
funzioni e list
. Anziché richiamare queste funzioni, l'uso di un riferimento alle risorse semplifica la sintassi e consente a Bicep di comprendere meglio il grafico delle dipendenze della distribuzione.
Codice regola Linter
Usa il seguente valore nel file di configurazione Bicep per personalizzare le impostazioni delle regole:
use-resource-symbol-reference
Soluzione
L'esempio seguente non supera questo test a causa dell’uso di reference
e 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 uppercase letter, one lowercase letter, and one non-alphanumeric character (except single-quote, double-quote, backslash, right-bracket, or full-stop characters). Also, the password must not contain three 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-05-01' existing = {
name: storageAccountName
}
resource cluster 'Microsoft.HDInsight/clusters@2024-08-01-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-05-01').primaryEndpoints.blob, 'https://', ''), '/', '')
isDefault: true
container: clusterName
key: listKeys(storageAccount.id, '2023-05-01').keys[0].value
}
]
}
}
}
È possibile risolvere il problema usando il riferimento alle risorse:
@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 uppercase letter, one lowercase letter, and one non-alphanumeric character (except single-quote, double-quote, backslash, right-bracket, or full-stop characters). Also, the password must not contain three 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-05-01' existing = {
name: storageAccountName
}
resource cluster 'Microsoft.HDInsight/clusters@2024-08-01-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
}
]
}
}
}
Usare Correzione rapida per semplificare la sintassi:
Passaggi successivi
Per ulteriori informazioni su linter, vedere Usare linter di Bicep.