Open ekUSA opened 2 years ago
@ekUSA , thanks for raising this issue.
I found seems your above terraform configuration is incorrect. There are many properties which are not in azurerm_monitor_scheduled_query_rules_log
resource.
The example of Terraform document only expose the basic scenario not full scenario.
As the import example shows, you have to pass the name of the azurerm_monitor_scheduled_query_rules_log
resource that is set in your terraform configuration file. So you cannot set it with query condition Daily M-F XYZ - Exception
. See below example.
After tried to import existing resource azurerm_monitor_scheduled_query_rules_log
, it succeeded with below terraform configuration and latest azurerm provider. Could you try below tf config to see if the issue still exists?
tf config:
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-monitor-test03"
location = "eastus"
}
resource "azurerm_log_analytics_workspace" "test" {
name = "acctestWorkspace-test03"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "PerGB2018"
retention_in_days = 30
}
resource "azurerm_monitor_scheduled_query_rules_log" "test" {
name = "acctest msqrl1"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
data_source_id = azurerm_log_analytics_workspace.test.id
criteria {
metric_name = "Average_% Idle Time"
dimension {
name = "InstanceName"
operator = "Include"
values = ["1"]
}
}
}
tf import:
terraform import azurerm_monitor_scheduled_query_rules_log.test "/subscriptions/xx-xx-xx-xx/resourceGroups/acctestRG-monitor-test03/providers/Microsoft.Insights/scheduledQueryRules/acctest msqrl1"
Result:
Community Note
Terraform (and AzureRM Provider) Version
Terraform v1.1.3 on windows_amd64
Affected Resource(s)
azurerm_monitor_scheduled_query_rules_log
Terraform Configuration Files
Debug Output
Panic Output
Expected Behaviour
Terraform should successfully import my existing App Insight Log Query Result Alert using this initial code for azurerm_monitor_scheduled_query_rules_log, so that I can figure out the correct option values and syntax for formatting to create other Azure Monitor Alerts
Actual Behaviour
Error: Wrong action type in Scheduled Query Rule "Daily M-F XYZ - Exception" (resource group "myRG"): insights.AlertingAction
Steps to Reproduce
terraform import azurerm_monitor_scheduled_query_rules_log.prod_alert "/subscriptions/xxxx/resourceGroups/myRG/providers/microsoft.insights/scheduledqueryrules/Daily M-F XYZ - Exception"
Important Factoids
in Azure Resource Graph Explorer, resources | where type == "microsoft.insights/scheduledqueryrules"
I see this for properties for the App Insight Log Query Monitor Alert I'm trying to import "odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction",
References
https://github.com/hashicorp/terraform-provider-azurerm/issues/3951
But this example does not have action_type: https://github.com/hashicorp/terraform-provider-azurerm/issues/7174
The Terraform AzureRM docs do not mention how to use action group block nor alert type for azurerm_monitor_scheduled_query_rules_log and what are possible values https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_log should include example with some query syntax and multiple action groups for the alert
0000