Home > Software engineering >  Azure Bicep - Subresource reference with resourceId()
Azure Bicep - Subresource reference with resourceId()

Time:11-15

I am deploying an App Gateway on Azure using a Bicep template (relevant pieces shown below).

var applicationGatewayId = resourceId('Microsoft.Network/applicationGateways', applicationGatewayName)
resource applicationGateway 'Microsoft.Network/applicationGateways@2021-08-01' = {
  properties: {
    urlPathMaps: [
      {
        properties: {
          defaultBackendAddressPool: {
            id: '${applicationGatewayId}/backendAddressPools/backendpool-test'
          }
      }
    ]
  }
}

My question is about the id of the backendAddressPool in the example. I get a warning when compiling: Warning use-resource-id-functions: If property "id" represents a resource ID, it must use a symbolic resource reference, be a parameter or start with one of these functions: extensionResourceId, guid, if, reference, resourceId, subscription, subscriptionResourceId, tenantResourceId. [https://aka.ms/bicep/linter/use-resource-id-functions].

  • I tried using ${applicationGateway.id}/backendAddressPools/backendpool-test, but that results in a cyclic reference error. For other resource types I used resourceId(), but for this example I wouldn't know how to.
  • I tried, e.g., resourceId('Microsoft.Network/ApplicationGatewayBackendAddressPool', '${prefix}-backendpool-infocat'), but that seems to result in a different resource type altogether (doesn't compile into the same id, at least).

This question is applicable to other subresources too, such as:

  • applicationGateway.urlPathMaps.defaultBackendAddressPool
  • applicationGateway.urlPathMaps.pathRules.backendAddressPool
  • applicationGateway.urlPathMaps.pathRules.backendHttpSettings
  • ...

So how does one refer to these subresources properly, when there's no readily defined resourceType to be used in resourceId()? Can the warnings be avoided?

Thanks in advance!

CodePudding user response:

Try this:

id:resourceId('Microsoft.Network/applicationGateways/backendAddressPools', applicationGatewayName, applicationGatewayBackendAddressPoolName)
  • Related