Exercise - Trigger a logic app by using Event Grid

Completed

One easy way to use Azure Event Grid is to include it in a logic app.

Suppose you've chosen to use Event Grid to alert your administrators when a virtual machine is reconfigured.

Here, you'll set up a virtual machine and create a logic app with an Event Grid trigger that responds to the events produced by the virtual machine.

Create a virtual machine

Let's start by creating a new virtual machine in the Azure portal.

  1. Sign in to the Azure portal with the account that you used to activate the sandbox.

  2. In resource menu or on the home page, under Azure services, select Create a resource. The Create a resource pane appears.

  3. In the left menu pane, select Compute, and in the results list, select Virtual machine. The Create a virtual machine pane appears.

  4. On the Basics tab, enter the following values for each setting:

    Setting Value
    Project details
    Subscription Concierge subscription
    Resource group From the dropdown list, select [sandbox resource group]
    Instance details
    Virtual machine name vm1
    Region Select a region near you
    Availability options No infrastructure redundancy required
    Security type Standard
    Image Windows Server 2019 Datacenter - Gen2
    Azure Spot instance No checkmark
    Size Standard DS1 v2
    Administrator account
    Username vmadmin
    Password Enter a complex password
    Inbound port rules
    Public inbound ports None
  5. Select Review and create. Once validation passes, select Create.

    Wait for deployment to complete, and then select Go to resource. The Overview pane for vm1 Virtual machine appears.

Create a logic app

Let's create a logic app that will run whenever a virtual machine change is detected. First, we'll create a blank logic app.

  1. In the resource menu, select Create a resource. The Create a resource pane appears.

  2. In the Create a resource menu, select Integration, and then in the results list, select Logic App. The Create Logic App pane appears.

  3. On the Basics tab, enter the following values for each setting.

    Setting Value
    Project Details
    Subscription Concierge subscription
    Resource group From the dropdown list, select [sandbox resource group]
    Instance Details
    Type Consumption
    Logic app name Enter a name
    Region Select a region near you
    Enable log analytics No
  4. Select Review + create, then select Create.

  5. Wait for deployment to complete, then select Go to resource. The Logic Apps Designer pane appears.

Add an Event Grid trigger to the logic app

  1. In the Logic Apps Designer pane, scroll down to Templates section, then select Blank Logic App. The Logic Apps Designer pane appears.

    Template for a blank logic app.

  2. In the Search connectors and triggers search box, enter event grid as your filter. From the list of triggers, select When a resource event occurs.

    Selections for adding an Event Grid trigger.

  3. When prompted, sign in to the Microsoft Learn Sandbox organization using your Azure account credentials.

  4. The When a resource event occurs dialog box appears. Select the following values for each setting to subscribe your logic app to publisher events:

    Setting Value
    Subscription Concierge Subscription
    Resource Type Microsoft.Resources.ResourceGroups
    Resource Name [sandbox resource group]
    Event Type Item - 1 Microsoft.Resources.ResourceActionSuccess, then select Add new item
    Event Type Item - 2 Microsoft.Resources.ResourceDeleteSuccess, then select Add new item
    Event Type Item - 3 Microsoft.Resources.ResourceWriteSuccess

    Trigger details.

  5. On the command bar, select Save.

    Save menu button.

Your logic app is now ready and set up to be a subscriber to the events from the Azure Event Grid.