Terraform | run KQL query on Azure Monitor Log Analytics

I want to show the logs from the Azure Monitor log analytics workspace using Terraform.
I see in the doc these AZ CLI commands (Link):

Execute a simple query over past 3.5 days :

az monitor log-analytics query -w workspace-customId --analytics-query "AzureActivity | summarize count() by bin(timestamp, 1h)" -t P3DT12H

Execute a saved query in workspace :

QUERY=$(az monitor log-analytics workspace saved-search show -g resource-group --workspace-name workspace-name -n query-name --query query --output tsv)

az monitor log-analytics query -w workspace-customId --analytics-query "$QUERY"

Is it possible to do this using Terraform? (run KQL query in Azure monitor or run saved search)
For the moment, I create just a saved search but I don’t know how to run it.

Just show log entries and no need to create an alert.


You can execute some commands using null_resource and the local-exec provisioner.