|
1 |
| ---- |
2 |
| -page_type: sample |
3 |
| -languages: |
4 |
| -- csharp |
5 |
| -- yaml |
6 |
| -products: |
7 |
| -- dotnet |
8 |
| -- dotnet-core |
9 |
| -- azure-functions |
10 |
| -- azure-event-grid |
11 |
| -- azure-storage |
12 |
| -- azure-blob-storage |
13 |
| -- azure-devops |
14 |
| ---- |
15 |
| - |
16 |
| -# Subscribing an Azure Function to Event Grid Events via Terraform |
17 |
| - |
18 |
| -This sample will show you how to create Terraform scripts that create an Azure Function and Subscribe it to Event Grid Storage events. |
19 |
| -This is especially interesting as, for Event Grid Subscriptions, the target endpoint must answer EG's "[Subscription Validation Event](https://docs.microsoft.com/en-us/azure/event-grid/security-authentication#validation-details)" which it cannot do until it is deployed. So this method - affectionally coined a "Terraform Sandwich" - shows how to do just that. |
20 |
| - |
21 |
| -## Deploying locally |
22 |
| -1. Open the repo in its VS Code Dev Container (this ensures you have all the right versions of the necessary tooling) |
23 |
| -1. run `az login` and `az account set --subscription <target subscription id>` to connect to your Azure Subscription |
24 |
| -1. `cd infrastructure/terraform` |
25 |
| -1. run `terraform init` |
26 |
| -1. run `terraform apply -var 'prefix=<some unique prefix here>' -target module.functions` |
27 |
| -1. `cd ../../src/FunctionApp` |
28 |
| -1. run `func azure functionapp publish <the name of the functionapp outputted by terraform apply> --csharp` |
29 |
| -1. `cd ../../infrastructure/terraform` |
30 |
| -1. run `terraform apply -var 'prefix=<same prefix as before>'` |
31 |
| - |
32 |
| -### What it does |
33 |
| -- Tells terraform to run everything **except** the event grid subscription piece |
34 |
| -- Deploys the function app out to Azure so it's ready to answer the subscription wire-up that Terraform will do next |
35 |
| -- Tells terraform to apply **everything**, which issues the necessary changes to Azure to add the event grid subscription to an 'inbox' storage account |
36 |
| - |
37 |
| -## Deploying via Azure DevOps |
38 |
| -By importing the [azure-piplines.yaml](./azure-pipelines.yaml) file in to an Azure DevOps pipeline, you'll get the same process as the above local execution. |
39 |
| -> Note: Be sure to uncomment change [the `PREFIX` variable](./azure-pipelines.yml#L10) to something unique to you to avoid naming collisions on storage & function apps |
40 |
| -
|
41 |
| -<img src="img/azdo_run.png" alt="Azure DevOps successful run" width="200"/> |
42 |
| - |
43 |
| -## Running the sample |
44 |
| -This sample has an Azure Function that subscribes to Blob Storage Events and then simply passes the event on to a custom Event Grid Topic. The receiving and sending of events is accomplished via the Event Grid Binding for Azure Functions. |
45 |
| - |
46 |
| -To exercise the sample: |
47 |
| -1. Open the 'inbox' storage account created by the deployment |
48 |
| -1. Create a new container |
49 |
| -1. Upload a file in to the container |
50 |
| - |
51 |
| -Next, go to the Azure Portal, and the Storage Account created by the deployment. Click the 'Events' area and you will see one or more events have come through: |
52 |
| - |
53 |
| -<img src="img/azstorevents.png" alt="Azure Portal Storage Events area" width="600"/> |
54 |
| - |
55 |
| -Then go to the custom topic created by deployment, and you'll see that one or more events have been posted to it: |
56 |
| - |
57 |
| -<img src="img/azcustomtopicevents.png" alt="Azure Portal Custom Topic Events area" width="600"/> |
58 |
| - |
59 |
| -Finally, if you wish to see the output from the Function, go to the Application Insights resource created by deployment and look through the logged TRACE events: |
60 |
| - |
| 1 | +--- |
| 2 | +page_type: sample |
| 3 | +languages: |
| 4 | +- csharp |
| 5 | +- yaml |
| 6 | +products: |
| 7 | +- dotnet |
| 8 | +- dotnet-core |
| 9 | +- azure-functions |
| 10 | +- azure-event-grid |
| 11 | +- azure-storage |
| 12 | +- azure-blob-storage |
| 13 | +- azure-devops |
| 14 | +--- |
| 15 | + |
| 16 | +# Subscribing an Azure Function to Event Grid Events via Terraform |
| 17 | + |
| 18 | +This sample will show you how to create Terraform scripts that create an Azure Function and Subscribe it to Event Grid Storage events. |
| 19 | +This is especially interesting as, for Event Grid Subscriptions, the target endpoint must answer EG's "[Subscription Validation Event](https://docs.microsoft.com/en-us/azure/event-grid/security-authentication#validation-details)" which it cannot do until it is deployed. So this method - affectionally coined a "Terraform Sandwich" - shows how to do just that. |
| 20 | + |
| 21 | +## Deploying locally |
| 22 | +1. Open the repo in its VS Code Dev Container (this ensures you have all the right versions of the necessary tooling) |
| 23 | +1. run `az login` and `az account set --subscription <target subscription id>` to connect to your Azure Subscription |
| 24 | +1. `cd infrastructure/terraform` |
| 25 | +1. run `terraform init` |
| 26 | +1. run `terraform apply -var prefix=<some unique prefix here> -target module.functions` |
| 27 | +1. `cd ../../src/FunctionApp` |
| 28 | +1. run `func azure functionapp publish <the name of the functionapp outputted by terraform apply> --csharp` |
| 29 | +1. `cd ../../infrastructure/terraform` |
| 30 | +1. run `terraform apply -var prefix=<same prefix as before>` |
| 31 | + |
| 32 | +### What it does |
| 33 | +- Tells terraform to run everything **except** the event grid subscription piece |
| 34 | +- Deploys the function app out to Azure so it's ready to answer the subscription wire-up that Terraform will do next |
| 35 | +- Tells terraform to apply **everything**, which issues the necessary changes to Azure to add the event grid subscription to an 'inbox' storage account |
| 36 | + |
| 37 | +## Deploying via Azure DevOps |
| 38 | +By importing the [azure-piplines.yaml](./azure-pipelines.yaml) file in to an Azure DevOps pipeline, you'll get the same process as the above local execution. |
| 39 | +> Note: Be sure to change [the `PREFIX` variable](./azure-pipelines.yml#L10) to something unique to you to avoid naming collisions on storage & function apps |
| 40 | +
|
| 41 | +<img src="img/azdo_run.png" alt="Azure DevOps successful run" width="200"/> |
| 42 | + |
| 43 | +## Running the sample |
| 44 | +This sample has an Azure Function that subscribes to Blob Storage Events and then simply passes the event on to a custom Event Grid Topic. The receiving and sending of events is accomplished via the Event Grid Binding for Azure Functions. |
| 45 | + |
| 46 | +To exercise the sample: |
| 47 | +1. Open the 'inbox' storage account created by the deployment |
| 48 | +1. Create a new container |
| 49 | +1. Upload a file in to the container |
| 50 | + |
| 51 | +Next, go to the Azure Portal, and the Storage Account created by the deployment. Click the 'Events' area and you will see one or more events have come through: |
| 52 | + |
| 53 | +<img src="img/azstorevents.png" alt="Azure Portal Storage Events area" width="600"/> |
| 54 | + |
| 55 | +Then go to the custom topic created by deployment, and you'll see that one or more events have been posted to it: |
| 56 | + |
| 57 | +<img src="img/azcustomtopicevents.png" alt="Azure Portal Custom Topic Events area" width="600"/> |
| 58 | + |
| 59 | +Finally, if you wish to see the output from the Function, go to the Application Insights resource created by deployment and look through the logged TRACE events: |
| 60 | + |
61 | 61 | <img src="img/azloggedevents.png" alt="Azure Portal Custom Topic Events area" width="600"/>
|
0 commit comments