azure-bicep

How to assign a private endpoint to a web.app slot using bicep script


I have a application defined as and I am trying to figure out how to map the preview slot to

resource app 'Microsoft.Web/sites@2022-09-01' = {
  name: '${appName}-${env}'
  location: location

  identity: {
    type: 'SystemAssigned'
  }

  properties: {
    serverFarmId: servicePlanId
    httpsOnly: true
    // clientAffinityEnabled: false
    virtualNetworkSubnetId: subnetId

    siteConfig: {
      ftpsState: 'Disabled'
      minTlsVersion: '1.2'
      publicNetworkAccess: 'Disabled'
    }
  }
}

Now I have defined a slot

resource stagingSlot 'Microsoft.Web/sites/slots@2021-02-01' = {
  name: 'preview'
  parent: app
  location: location
  kind: 'app'
  properties: {
    serverFarmId: servicePlanId
  }
}

Now I need to create a private endpoint for the main site and for the slot.

the slot gets created and the endpoint connection also but only to the parent item not the release slot

resource stagingSlotEndpoint 'Microsoft.Web/sites/slots/privateEndpointConnections@2022-03-01' = {
  name: '${appName}-preview'
  kind: 'app'
  parent: stagingSlot
  properties: {
    privateLinkServiceConnectionState: {
      status: 'Approved'
      description: 'Auto-Approved'
      actionsRequired: 'None'
    }
  }
}

Solution

  • To assign a private endpoint connection to a web app slot, you need to use Microsoft.Web/sites/privateEndpointConnections resource type.

    Add below code to yours and it will work as expected.

    resource prodSiteEndpoint 'Microsoft.Web/sites/privateEndpointConnections@2022-03-01' = {
       name: 'app-produ'
       kind: 'app'
       parent: app
       properties: {
         privateLinkServiceConnectionState: {
         status: 'Approved'
         description: 'Auto-Approved'
         actionsRequired: 'None'
       }
    }
     dependsOn: [
       appConfigurationPrivateEndPoint
       appConfigurationPrivateDnsZoneGroup
      ]
    }
    

    enter image description here

    complete bicep code:

    param location string = 'eastus'
    param appConfigurationPrivateEp string = 'priend'
    param appdns string = 'priend-nic'
    resource appServicePlan 'Microsoft.Web/serverfarms@2020-12-01' existing = {
      name: 'uovh4pk4fceb6kic6v5wmtms62'
    }
    resource app 'Microsoft.Web/sites@2022-09-01' existing = {
      name: 'uovh4pk4fceb6'
    }
    
    resource appConfigurationPrivateEndPoint 'Microsoft.Network/privateEndpoints@2021-03-01' existing= {
      name: appConfigurationPrivateEp
    }
    resource appConfigurationPrivateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2021-03-01' existing= {
      parent: appConfigurationPrivateEp
      name: appdns
    }
    
    resource stagingSlot 'Microsoft.Web/sites/slots@2021-02-01' = {
      name: 'stagingpreviewbla'
      parent: app
      location: location
      kind: 'app'
      properties: {
        serverFarmId: appServicePlan.id
      }
    }
    resource stagingSlotEndpoint 'Microsoft.Web/sites/slots/privateEndpointConnections@2022-03-01' = {
      name: 'app-preview'
      kind: 'app'
      parent: stagingSlot
      properties: {
        privateLinkServiceConnectionState: {
          status: 'Approved'
          description: 'Auto-Approved'
          actionsRequired: 'None'
        }
      }
      dependsOn: [
        appConfigurationPrivateEndPoint
        appConfigurationPrivateDnsZoneGroup
      ]
    }
    resource prodSiteEndpoint 'Microsoft.Web/sites/privateEndpointConnections@2022-03-01' = {
      name: 'app-produ'
      kind: 'app'
      parent: app
      properties: {
        privateLinkServiceConnectionState: {
          status: 'Approved'
          description: 'Auto-Approved'
          actionsRequired: 'None'
        }
      }
      dependsOn: [
        appConfigurationPrivateEndPoint
        appConfigurationPrivateDnsZoneGroup
      ]
    }