Configuring Logs for AVD Hostpools and Workspaces with Terraform
This post explains how to use Terraform to apply diagnostic settings for Azure Virtual Desktop (AVD) Hostpools and Workspaces. This code collects all the logs (using the Log Category “allLogs”) and pushes them to a Log Analytics Workspace
With the code below replace target_resource_id
and log_analytics_workspace_id
with the relevant values. These examples include a mix of azurerm, Azure Verified Modules (AVM), and straight variables for these parameters but pick whatever is suitable for the development in question.
Host Pool
1#Logs for Hostpool to Log Analytics Workspace
2resource "azurerm_monitor_diagnostic_setting" "hostpool" {
3 name = "sendTo-LogAnalytics"
4 target_resource_id = module.avm-res-desktopvirtualization-myhostpool.resource_id
5 #If using regular AzureRM in place of AVM that ID would be azurerm_virtual_desktop_host_pool.myhostpool.id
6 log_analytics_workspace_id = var.workspace_id
7 enabled_log {
8 category_group = "allLogs"
9 }
10}
Workspace
1#Logs for Workspace to Log Analytics Workspace
2resource "azurerm_monitor_diagnostic_setting" "workspace" {
3 name = "sendTo-LogAnalytics"
4 target_resource_id = module.avm-res-desktopvirtualization-myworkspace.resource.id
5 log_analytics_workspace_id = var.workspace_id
6 enabled_log {
7 category_group = "allLogs"
8 }
9}