Linter-regel: bronsymboolverwijzing gebruiken
Met deze regel worden suboptimale toepassingen van de reference
en list
functies gedetecteerd. In plaats van deze functies aan te roepen, vereenvoudigt het gebruik van een resourceverwijzing de syntaxis en kan Bicep uw afhankelijkheidsgrafiek van uw implementatie beter begrijpen.
Linter-regelcode
Gebruik de volgende waarde in het Bicep-configuratiebestand om regelinstellingen aan te passen:
use-resource-symbol-reference
Oplossing
In het volgende voorbeeld mislukt deze test vanwege het gebruik van reference
en 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
}
]
}
}
}
U kunt het probleem oplossen met behulp van resourcereferenties:
@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
}
]
}
}
}
U kunt het probleem automatisch oplossen door Snelle oplossing te selecteren, zoals wordt weergegeven in de volgende schermopname:
Volgende stappen
Zie Bicep linter gebruiken voor meer informatie over de linter.
Feedback
https://aka.ms/ContentUserFeedback.
Binnenkort beschikbaar: In de loop van 2024 zullen we GitHub-problemen geleidelijk uitfaseren als het feedbackmechanisme voor inhoud en deze vervangen door een nieuw feedbacksysteem. Zie voor meer informatie:Feedback verzenden en weergeven voor