Linter 규칙 - 리소스 기호 참조 사용

이 규칙은 referencelist 함수의 최적이 아닌 사용을 검색합니다. 이러한 함수를 호출하는 대신 리소스 참조를 사용하면 구문이 간소화되고 Bicep이 배포 종속성 그래프를 더 잘 이해할 수 있습니다.

Linter 규칙 코드

Bicep 구성 파일의 다음 값을 사용하여 규칙 설정을 사용자 지정합니다.

use-resource-symbol-reference

솔루션

다음 예제에서는 referencelistKey의 사용 때문에 이 테스트에 실패합니다.

@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
        }
      ]
    }
  }
}

리소스 참조를 사용하여 문제를 해결할 수 있습니다.

@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
        }
      ]
    }
  }
}

다음 스크린샷과 같이 빠른 수정을 선택하여 문제를 자동으로 해결할 수 있습니다.

리소스 기호 참조 빠른 수정 사용 스크린샷

다음 단계

Linter에 관한 자세한 내용은 Bicep Linter 사용을 참조하세요.