DEV Community

Massimo Bonanni
Massimo Bonanni

Posted on • Updated on

Use Bicep template to deploy EventGridViewer

When you use Azure Event Grid in your demos, labs or POCs, you need a simple client to check if the events you route are correctly routed.
One of the most useful client is Event Grid Viewer (GirHub Repo).
The following Bicep template allow you to deploy a free (F1) App Service and publish the last version of the client.

@description('The location where you want to create the resources.')
param location string = resourceGroup().location

@description('The name of the environment. It will be used to create the name of the resources in the resource group.')
@maxLength(16)
@minLength(3)
param environmentName string = '${uniqueString(resourceGroup().id)}'

//-------------------------------------------------------------
// EventGrid Event Viewer
//-------------------------------------------------------------
var eventViewerAppName =toLower('${environmentName}-eventviewer')
var eventViewerAppPlanName=toLower('${environmentName}-eventviewerplan')
var viewerRepoUrl = 'https://github.com/azure-samples/azure-event-grid-viewer.git'

resource eventViewerAppServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: eventViewerAppPlanName
  location: location
  sku: {
    name: 'F1'
    tier: 'Free'
    size: 'F1'
    family: 'F'
    capacity: 0
  }
  properties: {}
  kind: 'app'
}

resource eventViewerAppService 'Microsoft.Web/sites@2022-03-01' = {
  name: eventViewerAppName
  location: location
  kind: 'app'
  properties: {
    serverFarmId: eventViewerAppServicePlan.id
    hostNameSslStates: [
      {
        hostType: 'Standard'
        sslState: 'Disabled'
        name: '${eventViewerAppName}.azurewebsites.net'
      }
      {
        hostType: 'Standard'
        sslState: 'Disabled'
        name: '${eventViewerAppName}.scm.azurewebsites.net'
      }
    ]
    siteConfig: {
      ftpsState: 'FtpsOnly'
      minTlsVersion: '1.2'
    }
    httpsOnly: true
  }
}

resource eventViewerAppServiceDeploy 'Microsoft.Web/sites/sourcecontrols@2022-03-01' = {
  parent: eventViewerAppService
  name: 'web'
  properties: {
    repoUrl: viewerRepoUrl
    branch: 'main'
    isManualIntegration: true
  }
}

output eventGridViewerSubscriptionEndpoint string ='https://${eventViewerAppService.properties.defaultHostName}/api/updates' 
Enter fullscreen mode Exit fullscreen mode

The output of the template is the endpoint you can use in the webhook endpoint for the Event Grid subscription.
You can find the full tutorial (that uses ARM templates) in the link Event Grid Viewer tutorial.

You can deploy the template using the following command:

az deployment group create --resource-group <resource group name> --template-file eventGridViewer.bicep
Enter fullscreen mode Exit fullscreen mode

where

  • <resource group name> is the name of the resource group in which you want to deploy the event grid viewer

You can also set these parameters:

  • location : the location you want to deploy (by default the location is the location of the resourcegroup)
  • environmentName : the prefix used to create all the resources in the resource group. By default it is setted to 'sts' with a unique value.
az deployment group create --resource-group <resource group name> --template-file eventGridViewer.bicep --parameters location=<location to deploy> environmentName=<env name>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)