Linter-regel : resource-id-functies gebruiken

Zorgt ervoor dat de id van een symbolische resourcenaam of een geschikte functie wordt gebruikt in plaats van een handmatig gemaakte id, zoals een samenvoegingstekenreeks, voor alle eigenschappen die een resource-id vertegenwoordigen. Gebruik waar mogelijk symbolische namen van resources.

De toegestane functies zijn onder andere:

Linter-regelcode

Gebruik de volgende waarde in het Bicep-configuratiebestand om regelinstellingen aan te passen:

use-resource-id-functions

Oplossing

In het volgende voorbeeld is deze test mislukt omdat de eigenschap van de resource gebruikmaakt van api/id een handmatig gemaakte tekenreeks:

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

U kunt dit probleem oplossen met behulp van de subscriptionResourceId() functie:

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

Volgende stappen

Zie Bicep linter gebruiken voor meer informatie over de linter.