Exercise - Trigger a logic app by using Event Grid
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.
Sign in to the Azure portal with the account that you used to activate the sandbox.
In resource menu or on the home page, under Azure services, select Create a resource. The Create a resource pane appears.
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.
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
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.
In the resource menu, select Create a resource. The Create a resource pane appears.
In the Create a resource menu, select Integration, and then in the results list, select Logic App. The Create Logic App pane appears.
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
Select Review + create, then select Create.
Wait for deployment to complete, then select Go to resource. The Overview pane appears.
Add an Event Grid trigger to the logic app
In the menu on the left, select Logic app designer in the Development Tools section.
Scroll down to Templates section, then select Blank Logic App. The Logic Apps Designer pane appears.
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.
When prompted, sign in to the Microsoft Learn Sandbox organization using your Azure account credentials.
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 itemEvent Type Item - 2 Choose Microsoft.Resources.ResourceDeleteSuccess
from the drop-down, then select Add new itemEvent Type Item - 3 Choose Microsoft.Resources.ResourceWriteSuccess
from the drop-down.On the command bar, select Save.
Your logic app is now ready and set up to be a subscriber to the events from the Azure Event Grid.