Azure / Azure-Functions

1.12k stars 199 forks source link

Deploy a function app with an Event Grid subscription in a single ARM template #1004

Open paulbatum opened 6 years ago

paulbatum commented 6 years ago

It needs to be possible to create a V2 function app, along with an Event Grid subscription that is configured to deliver events to the function app, all within a single ARM template. Today this is difficult to due limitations with the functions ARM keys API (discussed here).

nhart12 commented 6 years ago

I have successfully gotten this to work, but requires two arm templates with a powershell script in between to extract the eventgrid key from https://.azurewebsites.net/admin/host/systemkeys/eventgrid_extension

vladislav-mitev commented 5 years ago

This is definitely a must!

paulbatum commented 5 years ago

We're making some progress on enabling this, using key vault as the mechanism of key storage. We have most of the pieces in PR and we're doing some end to end testing. @mattchenderson is going to post an example here once he has an ARM template using this that works.

davidbellemare commented 5 years ago

Any update on this?

mathewc commented 5 years ago

The ARM key management portion of this issue has been addressed - there are now APIs for getting the required system key for the EventGrid subscription. However, there is still a race condition issue tracked by https://github.com/Azure/azure-functions-host/issues/4661 which still needs to be addressed.

alex-nanai commented 4 years ago

Seems like race condition issue is now closed? Couldn't find documentation on the topic raised.

paulbatum commented 4 years ago

@mattchenderson Have you taken another look at this now that all the pending issues have been resolved?

mathewc commented 4 years ago

This should be unblocked now. The API doc for host keys is here: Web Apps - List Host Keys. That API returns both master key and system keys. Also, @jcbrooks92 has published a sample template here which shows how to use these APIs to create an EventGrid subscription. I think we're good to close this now.

briandunnington commented 4 years ago

@mathewc The sample from @jcbrooks92 only appears to work if the Function is already deployed and running (which appears to generate the event grid system key). The original request from @paulbatum is requesting the ability to create the Function and Subscription in the same ARM template - is that possible yet? If so, is there an example ARM template that demonstrates how?

jcbrooks92 commented 4 years ago

@briandunnington this behavior is what's expected with Eventgrid (@mathewc can confirm). By default v2 functions do not have all the extensions installed so they must be installed manually or have code deployed that contains the extensions. In my sample I use run from package to deploy the default Eventgrid function. Something I haven't tried yet was using bundles but this would still require a code deployment.

briandunnington commented 4 years ago

@jcbrooks92 Understood that this is currently how it works. I think this issue is more of a feature request to change the behavior so that it is possible to deploy the Event Grid subscription at the same time (in the same ARM template) as the Function app.

paulbatum commented 4 years ago

What if the ARM template configured the function app to use run-from-package via an appsetting, pointing at a blob. That way the content including the eventgrid extension would already be present. Anyone had a chance to try this?

jcbrooks92 commented 4 years ago

@paulbatum I've tested this out in my example template. As long as the correct dependency flow is setup (Eventgrid dependsOn function app), I believe it should deploy in time. Granted I've only used a very simple function with one eventgrid trigger.

https://github.com/jcbrooks92/EventGridAzureFunctionARMTemplate/blob/194a3c7fabcc7ef85ebcb9d4288a9653adda8846/azuredeploy.json#L173