Search code examples
azure-bicep

How to reference a WAF probe by symbolicName rather than as a string


I'm trying to deploy an Azure Application Gateway using bicep. I've exported the ARM template and converted it to bicep using VS Code (paste into a .bicep file to have Code automatically convert it).

I'm going through the process of trying to tidy it up and I'm stuck how to reference a Probe from a backendHttpSettingsCollection entry. In the code snippet below I've got a backendHttpSettings item 'Be_Settings_HTTPS' and a probe 'Be_HealthProbe', the probe is referenced from the httpSettings using an interpolated string for the Id which gives me an error stating

"This expression is referencing its own declaration, which is not allowed."

Is it possible to reference this using a symbolic name?

Current bicep snippet

resource agw_foo_resource 'Microsoft.Network/applicationGateways@2023-05-01' = {
    name: 'FooAGW'
    location: location
    ...
    properties: {
        backendHttpSettingsCollection: [
            {
                name: 'Be_Settings_HTTPS'
                properties: {
                    port: 443
                    protocol: 'Https'
                    cookieBasedAffinity: 'Disabled'
                    pickHostNameFromBackendAddress: true
                    affinityCookieName: 'ApplicationGatewayAffinity'
                    requestTimeout: 20
                    probe: {
// How can I reference the "Be_HealthProbe" without having to use string interpolation?
                        id: '${applicationGateways_agw_prod_uks_01_name_resource.id}/probes/Be_HealthProbe'
                    }
                }
            }
        probes: [
            {
                name: 'Be_HealthProbe'
                properties: {
                    protocol: 'Https'
                    path: '/'
                    interval: 30
                    timeout: 30
                    unhealthyThreshold: 3
                    pickHostNameFromBackendHttpSettings: true
                    minServers: 0
                    match: {
                        statusCodes: [
                            '200-399'
                        ]
                    }
                }
            }
    }

Solution

  • I don't think you can refer probe id using '(symolic probe resource name).id' here. because arm template seems not support independently deployment of the probe resource. so the workaround is to use "resourceId". such as below:

      resource ApplicationGateway 'Microsoft.Network/applicationGateways@2022-07-01' = {
      name: applicationGatewayNameResource
      location: location
      properties: {
        sku: {
          name: 'Standard_v2'
          tier: 'Standard_v2'
          capacity: 2
        }
        gatewayIPConfigurations: [
          {
            name: 'appGatewayIpConfig'
            properties: {
              subnet: {
                id: subnetRef
              }
            }
          }
        ]
        frontendIPConfigurations: [
          {
            name: 'appGatewayFrontendIP'
            properties: {
              publicIPAddress: {
                id: publicIPRef
              }
            }
          }
        ]
        frontendPorts: [
          {
            name: 'appGatewayFrontendPort'
            properties: {
              port: 80
            }
          }
        ]
        backendAddressPools: [
          {
            name: 'appGatewayBackendPool'
            properties: {
              backendAddresses: [
                {
                  ipAddress: AppService.properties.defaultHostName
                }
              ]
            }
          }
        ]
        backendHttpSettingsCollection: [
          {
            name: 'appGatewayBackendHttpSettings'
            properties: {
              port: 80
              hostName: '${siteName}.azurewebsites.net'
              protocol: 'Http'
              cookieBasedAffinity: 'Disabled'
              pickHostNameFromBackendAddress: false
              probeEnabled: true
              probe: {
                id: resourceId('Microsoft.Network/applicationGateways/probes/', applicationGatewayNameResource, 'Probe1')
              }
            }
          }
        ]
        httpListeners: [
          {
            name: 'appGatewayHttpListener'
            properties: {
              frontendIPConfiguration: {
                id: resourceId('Microsoft.Network/applicationGateways/frontendIPConfigurations/', applicationGatewayNameResource, 'appGatewayFrontendIP')
              }
              frontendPort: {
                id: resourceId('Microsoft.Network/applicationGateways/frontendPorts/', applicationGatewayNameResource, 'appGatewayFrontendPort')
              }
              protocol: 'Http'
            }
          }
        ]
        probes: [
          {
            name: 'Probe1'
            properties: {
              protocol: 'Http'
              path: '/'
              interval: 30
              timeout: 10
              unhealthyThreshold: 3
              minServers: 0
              pickHostNameFromBackendHttpSettings: true
            }
          }
        ]
      }
      dependsOn: [
        virtualNetworkName
    
      ]
    }
    

    pay attention to probe1, and reference docs