page_type | languages | products | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
This sample will show you how to create Terraform scripts that create an Azure Function and Subscribe it to Event Grid Storage events. This is especially interesting as, for Event Grid Subscriptions, the target endpoint must answer EG's "Subscription Validation Event" which it cannot do until it is deployed. So this method - affectionally coined a "Terraform Sandwich" - shows how to do just that.
- Open the repo in its VS Code Dev Container (this ensures you have all the right versions of the necessary tooling)
- run
./deploy.sh <target subscription id> <unique prefix>
- Logs in to Azure and connects to the target subscription
- Tells terraform to deploy everything except the event grid subscription piece
- Deploys the function app out to Azure so it's ready to answer the subscription wire-up that Terraform will do next
- Tells terraform to deploy everything, which issues the necessary changes to Azure to add the event grid subscription to an 'inbox' storage account
By importing the azure-piplines.yaml file in to an Azure DevOps pipeline, you'll get the same process as the above local execution.
Note: Be sure to change the
PREFIX
variable to something unique to you to avoid naming collisions on storage & function apps
You'll need to create a Service Connection in Azure DevOps:
- Click Project settings (bottom left)
- Click Service connections
- Click Create service connection
- Select Azure Resource Manager
- Select Service Principal (automatic)
- Enter Service Connection name
my-azure
(Note: you can leave Resource group blank) - Ensure Grant access permissions to all pipelines is checked
Run the pipeline:
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.
To exercise the sample:
- Open the 'inbox' storage account created by the deployment
- Create a new container
- Upload a file in to the container
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:
Then go to the custom topic created by deployment, and you'll see that one or more events have been posted to it:
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: