Linter-regel – använd resurs-ID-funktioner

Säkerställer att ID:t för ett symboliskt resursnamn eller en lämplig funktion används i stället för ett manuellt skapat ID, till exempel en sammanlänkande sträng, för alla egenskaper som representerar ett resurs-ID. Använd symboliska resursnamn när det är möjligt.

De tillåtna funktionerna är:

Linterregelkod

Använd följande värde i Bicep-konfigurationsfilen för att anpassa regelinställningar:

use-resource-id-functions

Lösning

Följande exempel misslyckas med det här testet eftersom resursens egenskap använder en sträng som skapats api/id manuellt:

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

Du kan åtgärda det med hjälp subscriptionResourceId() av funktionen:

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

Nästa steg

Mer information om linter finns i Använda Bicep-linter.