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 Create a resource pane, enter Virtual machine in global search. In the search results, select Virtual machine published by Microsoft for Azure, and then select Create.

  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 Choose from the free sandbox regions listed after this table.
    Availability options No infrastructure redundancy required
    Security type Standard
    Image Windows Server 2019 Datacenter - x64 Gen2
    Run with Azure Spot discount No checkmark
    Size Standard DS1 v2
    Administrator account
    Username vmadmin
    Password Enter a complex password
    Inbound port rules
    Public inbound ports None

    The free sandbox allows you to create resources in a subset of the Azure global regions. Select a region from the following list when you create resources:

    • West US 2
    • South Central US
    • Central US
    • East US
    • West Europe
    • Southeast Asia
    • Japan East
    • Brazil South
    • Australia Southeast
    • Central India
  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 runs 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
    Logic app name Enter a name
    Region Choose from the free sandbox regions listed after this table.
    Enable log analytics No
    Plan type Consumption

    The free sandbox allows you to create resources in a subset of the Azure global regions. Select a region from the following list when you create resources:

    • West US 2
    • South Central US
    • Central US
    • East US
    • West Europe
    • Southeast Asia
    • Japan East
    • Brazil South
    • Australia Southeast
    • Central India
  4. Select Review + create, then select Create.

  5. Wait for deployment to complete, then select Go to resource. The Overview pane appears.

Add an Event Grid trigger to the logic app

  1. In the menu on the left, select Logic app designer in the Development Tools section.

  2. Scroll down to Templates section, then select Blank Logic App. The Logic Apps Designer pane appears.

    Screenshot of the template for a blank logic app.

  3. 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.

    Screenshot of the selections for adding an Event Grid trigger.

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

  5. 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 Choose Microsoft.Resources.ResourceActionSuccess from the drop-down, then select Add new item
    Event Type Item - 2 Choose Microsoft.Resources.ResourceDeleteSuccessfrom the drop-down, then select Add new item
    Event Type Item - 3 Choose Microsoft.Resources.ResourceWriteSuccess from the drop-down.

    Screenshot of the trigger details.

  6. On the command bar, select Save.

    Screenshot of the Save menu button.

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