Event Handlers

[!TIP] Alternatively, you can use the azure_setup baseline to automate this process.

Event handlers provide near real-time event delivery from Azure to Guardrails. When a resource changes, Guardrails knows within seconds rather than waiting for the next polling interval. The event handler infrastructure is configured by a Turbot stack in each subscription, with two components:

Prerequisites

The following mods must be installed and up to date in the environment:

When configuring event handlers, specific roles must be assigned (or created) to ensure functionality. Review the section on Azure IAM Permissions and note the requirement of a custom role for Read-Only Turbot mode using event handlers.

The target subscription must have the Microsoft Insights provider registered for events to flow properly.

Step 1: Configure the Turbot Resource Group

Azure resources must be created in a Resource Group. Turbot can create a default resource group, turbot_rg, by configuring the policy Azure > Turbot > Resource Group to Enforce: Configured. Depending on organization requirements, this Resource Group can also be manually created. Please contact Turbot support if manual creation of the turbot_rg is desired.

# Create the Resource Group and set the policy
# Azure > Turbot > Resource Group
resource "turbot_policy_setting" "turbotResourceGroup" {
  resource          = id of your folder       // highlight-line
  type              = "tmod:@turbot/azure#/policy/types/turbotResourceGroup"
  value             = "Enforce: Configured"
}

Step 2: Enable Event Handlers

To set up Azure Event Handlers in the default configuration, set the Azure > Turbot > Event Handlers policy to Enforce: Configured.

# Create Event through Event Handler
# Azure > Turbot > Event Handlers
resource "turbot_policy_setting" "eventHandlers" {
  resource    = "id of parent folder or policy pack"   //highlight-line
  type            = "tmod:@turbot/azure#/policy/types/eventHandlers"
  value           = "Enforce: Configured"
}

The default configuration is sufficient for most cases, though you can use the Azure > Turbot Event Handlers > * sub-policies to customize the configuration to meet your requirements.

Step 3: Verify Event Handlers

Verify the state of Azure > Turbot > Event Handlers controls for each subscription.

After a few minutes, all controls should be in the OK state. If there are any in error or alarm, they should be investigated to ensure that Event Handling is working correctly.

Troubleshooting

IssueSolution
Event handler controls in errorVerify the Microsoft Insights provider is registered in the target subscription. Check that the required mods (azure, azure-iam, azure-provider, azure-monitor) are installed.
Events not flowing to GuardrailsConfirm the Action Group webhook URL points to the correct Guardrails endpoint. Check Activity Log Alert configuration in the Azure Portal.
Further assistanceContact Turbot Support if issues continue to persist.