GithubHelp home page GithubHelp logo

isabella232 / azure-functions-event-grid-terraform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/azure-functions-event-grid-terraform

0.0 0.0 0.0 1.17 MB

This sample shows how to create Storage Event subscriptions to Azure Functions, publish events to a custom Event Grid topic, and deploy it all with Terraform

License: MIT License

Dockerfile 34.17% HCL 51.34% C# 8.47% Shell 6.01%

azure-functions-event-grid-terraform's Introduction

page_type languages products
sample
csharp
yaml
dotnet
dotnet-core
azure-functions
azure-event-grid
azure-storage
azure-blob-storage
azure-devops

Subscribing an Azure Function to Event Grid Events via Terraform

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.

Deploying locally

  1. Open the repo in its VS Code Dev Container (this ensures you have all the right versions of the necessary tooling)
  2. run ./deploy.sh <target subscription id> <unique prefix>

What it does

  • 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

Deploying via Azure DevOps

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:

  1. Click Project settings (bottom left)
  2. Click Service connections
  3. Click Create service connection
  4. Select Azure Resource Manager
  5. Select Service Principal (automatic)
  6. Enter Service Connection name my-azure (Note: you can leave Resource group blank)
  7. Ensure Grant access permissions to all pipelines is checked

Run the pipeline:

Azure DevOps successful run

Running the sample

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:

  1. Open the 'inbox' storage account created by the deployment
  2. Create a new container
  3. 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:

Azure Portal Storage Events area

Then go to the custom topic created by deployment, and you'll see that one or more events have been posted to it:

Azure Portal Custom Topic Events area

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:

Azure Portal Custom Topic Events area

azure-functions-event-grid-terraform's People

Contributors

brandonh-msft avatar howlowck avatar microsoft-github-operations[bot] avatar tomhon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.