Skip to content

Commit 2bf2903

Browse files
Merge pull request #95988 from msmbaldwin/akv-logicapps
AKV / Event Grid / Logic Apps
2 parents 7438495 + a32620b commit 2bf2903

12 files changed

+97
-5
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: Email when Key Vault status of the secret changes
3+
description: Guide to use Logic Apps to respond to Key Vault secrets changes
4+
services: key-vault
5+
author: msmbaldwin
6+
manager: rkarlin
7+
tags: azure-resource-manager
8+
9+
ms.service: key-vault
10+
ms.topic: tutorial
11+
ms.date: 11/11/2019
12+
ms.author: mbaldwin
13+
14+
---
15+
# Use Logic Apps to receive email about status changes of key vault secrets
16+
17+
In this guide you will learn how to respond to Azure Key Vault events that are received via [Azure Event Grid](../event-grid/index.yml) by using [Azure Logic Apps](../logic-apps/index.yml). By the end, you will have an Azure logic app set up to send a notification email every time a secret is created in Azure Key Vault.
18+
19+
For an overview of Azure Key Vault / Azure Event Grid integration, see [Monitoring Key Vault with Azure Event Grid (preview)](event-grid-overview.md).
20+
21+
## Prerequisites
22+
23+
- An email account from any email provider that is supported by Azure Logic Apps (such as Office 365 Outlook). This email account is used to send the event notifications. For a complete list of supported Logic App connectors, see the [Connectors overview](/connectors)
24+
- An Azure subscription. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
25+
- A key vault in your Azure Subscription. You can quickly create a new key vault by following the steps in [Set and retrieve a secret from Azure Key Vault using Azure CLI](quick-create-cli.md).
26+
27+
## Create a Logic App via Event Grid
28+
29+
First, create Logic App with event grid handler and subscribe to Azure Key Vault "SecretNewVersionCreated" events.
30+
31+
To create an Azure Event Grid subscription, follow these steps:
32+
33+
1. Open the Azure portal using the following link: https://portal.azure.com/?Microsoft_Azure_KeyVault_ShowEvents=true&Microsoft_Azure_EventGrid_publisherPreview=true
34+
1. In the Azure portal, go to your key vault, select **Events > Get Started** and click **Logic Apps**
35+
36+
37+
![Key Vault - events page](./media/eventgrid-logicapps-kvsubs.png)
38+
39+
1. On **Logic Apps Designer** validate the connection and click **Continue**
40+
41+
![Logic App Designer - connection](./media/eventgrid-logicappdesigner1.png)
42+
43+
1. On the **When a a resource event occurs** screen, do the following:
44+
- Leave **Subscription** and **Resource Name** as default.
45+
- Select **Microsoft.KeyVault.vaults** for the **Resource Type**.
46+
- Select **Microsoft.KeyVault.SecretNewVersionCreated** for **Event Type Item - 1**.
47+
48+
![Logic App Designer - event handler](./media/eventgrid-logicappdesigner2.png)
49+
50+
1. Select **+ New Step** This will open a window to Choose an action.
51+
1. Search for **Email**. Based on your email provider, find and select the matching connector. This tutorial uses **Office 365 Outlook**. The steps for other email providers are similar.
52+
1. Select the **Send an email (V2)** action.
53+
54+
![Logic App Designer - add email](./media/eventgrid-logicappdesigner3.png)
55+
56+
1. Build your email template:
57+
- **To:** Enter the email address to receive the notification emails. For this tutorial, use an email account that you can access for testing.
58+
- **Subject** and **Body**: Write the text for your email. Select JSON properties from the selector tool to include dynamic content based on event data. You can retrieve the data of the event using `@{triggerBody()?['Data']}`.
59+
60+
Your email template may look like this example.
61+
62+
![Logic App Designer - add email](./media/eventgrid-logicappdesigner4.png)
63+
64+
8. Click **Save as**.
65+
9. Enter a **name** for new logic app and click **Create**.
66+
67+
![Logic App Designer - add email](./media/eventgrid-logicappdesigner5.png)
68+
69+
## Test and verify
70+
71+
1. Go to your key vault on the Azure portal and select **Events > Event Subscriptions**. Verify that a new subscription created
72+
73+
![Logic App Designer - add email](./media/eventgrid-logicapps-kvnewsubs.png)
74+
75+
1. Go to your key vault, select **Secrets**, and select **+ Generate/Import**. Create a new secret for testing purposes name the key and keep the remaining parameters in their default settings.
76+
77+
![Key Vault - Create Secret](./media/eventgrid-logicapps-kv-create-secret.png)
78+
79+
1. On the **Create a secret** screen provide any name, any value, and select **Create**.
80+
81+
When the secret is created, an email will be received at the configured addresses.
82+
83+
## Next steps
84+
85+
- Overview: [Monitoring Key Vault with Azure Event Grid (preview)](event-grid-overview.md)
86+
- How to: [Route key vault notifications to Azure Automation](event-grid-tutorial.md).
87+
- [Azure Event Grid event schema for Azure Key Vault (preview)](../event-grid/event-schema-key-vault.md)
88+
- Learn more about [Azure Event Grid](../event-grid/index.yml).
89+
- Learn more about the [Logic Apps feature of Azure App Service](../logic-apps/index.yml).

articles/key-vault/event-grid-overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Applications that handle Key Vault events should follow a few recommended practi
4141

4242
- [Azure Key Vault overview](key-vault-overview.md)
4343
- [Azure Event Grid overview](../event-grid/overview.md)
44-
- [How to: Route Key Vault Events to Automation Runbook (preview)](event-grid-tutorial.md).
44+
- How to: [Route Key Vault Events to Automation Runbook (preview)](event-grid-tutorial.md).
45+
- How to: [Receive email when a key vault secret changes](event-grid-logicapps.md)
4546
- [Azure Event Grid event schema for Azure Key Vault (preview)](../event-grid/event-schema-key-vault.md)
4647
- [Azure Automation overview](../automation/index.yml)

articles/key-vault/event-grid-tutorial.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ If you've been using a polling-based system to search for status changes of secr
191191

192192
Learn more:
193193

194+
195+
- Overview: [Monitoring Key Vault with Azure Event Grid (preview)](event-grid-overview.md)
196+
- How to: [Receive email when a key vault secret changes](event-grid-logicapps.md)
197+
- [Azure Event Grid event schema for Azure Key Vault (preview)](../event-grid/event-schema-key-vault.md)
194198
- [Azure Key Vault overview](key-vault-overview.md)
195199
- [Azure Event Grid overview](../event-grid/overview.md)
196-
- [Monitoring Key Vault with Azure Event Grid (preview)](event-grid-overview.md)
197-
- [Azure Event Grid event schema for Azure Key Vault (preview)](../event-grid/event-schema-key-vault.md)
198200
- [Azure Automation overview](../automation/index.yml)
71.9 KB
Loading
129 KB
Loading
149 KB
Loading
101 KB
Loading
173 KB
Loading
29.8 KB
Loading
90.2 KB
Loading

0 commit comments

Comments
 (0)