Action Groups

Azure Action Groups are a feature in Microsoft Azure that allow you to define a set of actions to be executed when a particular event occurs. They enable automation and proactive management by triggering actions such as sending notifications, running Azure Functions, or executing custom logic based on events in your Azure environment.

Action Groups and Azure Function Apps

Action Groups in Azure can leverage Function Apps as one of the actions to be executed when a specific event occurs. By configuring an Action Group to invoke a Function App, you can automate custom logic or perform specific tasks based on the event trigger, allowing for powerful and flexible event-driven workflows in Azure.

Terraform

Ok now, how does it look in terraform.

# My function App
resource "azurerm_function_app" "example_function_app" {
  # Configuration properties for the Function App
  # ...
}

# My Action Group with Function App webhook
resource "azurerm_monitor_action_group" "example_action_group" {
  name                = "example-action-group"
  resource_group_name = "example-resource-group"

  webhook_properties {
    service_uri = azurerm_function_app.example_function_app.default_hostname
  }

  # Other configuration properties for the Action Group
  # ...
}

Problems, Problems, Problems…

As of today Using this configuration will result into an Unauthorized Error.

First Problem is that no attribute allows to pass the Fuction App host Keys in the webhook_properties block. Other problem is that the azurerm_function_app resource block does not export these keys.

First let’s get them using the data block that allows it.

data "azurerm_function_app_host_keys" "example_host_keys" {
  name                = azurerm_function_app.example_function_app.name
  resource_group_name = azurerm_function_app.example_function_app.resource_group_name
}

Then we can construct the service_uri using one of these keys.

resource "azurerm_monitor_action_group" "example_action_group" {

  webhook_properties {
    service_uri = "https://${azurerm_function_app.example_function_app.default_hostname}/api/MyFunction?code=${data.azurerm_function_app_host_keys.example_host_keys.some_key}"
  }

  # Other configuration properties for the Action Group
  # ...
}