In Terraform I have created a Azure Function App and under it one Function...this all works ok.
The Function code...
resource "azurerm_function_app_function" "example" {
depends_on = [module.create_fapp_re_id]
name = local.reid_function_name
function_app_id = module.create_fapp_re_id.function_app_id
config_json = jsonencode({
"bindings" = [
{
"authLevel" = "function"
"direction" = "in"
"methods" = [
"get",
"post",
]
"name" = "req"
"type" = "httpTrigger"
},
{
"direction" = "out"
"name" = "$return"
"type" = "http"
},
]
})
}
The Terraform EventGrid Subsription code..
resource "azurerm_eventgrid_event_subscription" "blob_created_sub" {
depends_on = [module.create_fapp_re_id]
name = "${var.env}-outbox-blob-created-sub"
scope = module.create_reid_storage_account.id
event_delivery_schema = "EventGridSchema"
azure_function_endpoint {
function_id = "${module.create_fapp_re_id.function_app_id}/functions/${local.reid_function_name}"
}
included_event_types = ["Microsoft.Storage.BlobCreated"]
# webhook_endpoint {
# url = "https://${module.create_reid_storage_account.name}.azurewebsites.net/api/ProjectOutboxEventFunction?code=${data.azurerm_function_app_host_keys.host_key.default_function_key}"
# }
advanced_filter {
string_contains {
values = ["outbox"]
key = "subject"
}
}
labels = ["blob", "outbox", "automation"]
}
I am then trying to create a 'Event Grid Subscription' that when a file is place in to a container within the Azure Storage Account the Azure Function App is fired...
When I run the Terraform Apply the creation of the 'Event Grid Subscription' fails with...
"Failed" "Unsupported Azure Function Trigger" "Can't add resource /subscriptions/XXX-XXX-XXX-XXX/resourceGroups/dummy-rg/providers/Microsoft.Web/sites/test-function-app/functions/ProjectOutboxEventFunction as a destination with unsupported Azure function triggers. Azure Event Grid supports EventGrid Trigger type only." ----[start]---- {"id":"https://management.azure.com/subscriptions/XXX-XXX-XXX-XXX/providers/Microsoft.EventGrid/locations/uksouth/operationsStatus/FB17FC7E-D332-46F2-8D21-FCB01B35C542?api-version=2022-06-15","name":"fb17fc7e-d332-46f2-8d21-fcb01b35c542","status":"Failed","error":{"code":"Unsupported Azure Function Trigger","message":"Can't add resource /subscriptions/XXX-XXX-XXX-XXX/resourceGroups/dummy-rg/providers/Microsoft.Web/sites/test-function-app/functions/ProjectOutboxEventFunction as a destination with unsupported Azure function triggers. Azure Event Grid supports EventGrid Trigger type only."}} -----[end]-----
Terraform failed to Create "azurerm_eventgrid_event_subscription" Linked to an Azure Function
Continuation from the comment section discussion, I can clearly see that you're deployed an Azure Function inside it, using an httpTrigger
. While you're linking Event Grid to your Function using an Event Subscription.
So when you're linking an event grid you can only directly invoke Azure Functions that are using an Event Grid Trigger but not with httpTrigger.
So the binding type which you mentioned in the configuration need to be updated with Event Grid Trigger. Which lacks in the configuration you shared and resulting in error.
Configuration:
resource "azurerm_function_app_function" "example" {
depends_on = [module.create_fapp_re_id]
name = local.reid_function_name
function_app_id = module.create_fapp_re_id.function_app_id
config_json = jsonencode({
"bindings" = [
{
"type" = "eventGridTrigger"
"direction" = "in"
"name" = "event"
}
]
})
}
Refer:
https://learn.microsoft.com/en-us/azure/event-grid/delivery-and-retry#azure-function-handlers