From c5aeb94dfd8c01f54894f5f07af9dfa2d657c24f Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 1 Sep 2021 16:40:12 -0400 Subject: [PATCH 01/18] Support for auto-mitigate for Azure scheduled_query #13036 --- ...tor_scheduled_query_rules_alert_resource.go | 18 +++++++++++++----- ...cheduled_query_rules_alert_resource_test.go | 2 ++ ...r_scheduled_query_rules_alert.html.markdown | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index 103580a0d783..963897903317 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -92,6 +92,11 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { Required: true, ValidateFunc: azure.ValidateResourceID, }, + "auto_mitigate": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, "description": { Type: pluginsdk.TypeString, Optional: true, @@ -239,6 +244,7 @@ func resourceMonitorScheduledQueryRulesAlertCreateUpdate(d *pluginsdk.ResourceDa } } + autoMitigate := d.Get("auto_mitigate").(bool) description := d.Get("description").(string) enabledRaw := d.Get("enabled").(bool) @@ -257,11 +263,12 @@ func resourceMonitorScheduledQueryRulesAlertCreateUpdate(d *pluginsdk.ResourceDa parameters := insights.LogSearchRuleResource{ Location: utils.String(location), LogSearchRule: &insights.LogSearchRule{ - Description: utils.String(description), - Enabled: enabled, - Source: source, - Schedule: schedule, - Action: action, + Description: utils.String(description), + Enabled: enabled, + Source: source, + Schedule: schedule, + Action: action, + AutoMitigate: &autoMitigate, }, Tags: expandedTags, } @@ -310,6 +317,7 @@ func resourceMonitorScheduledQueryRulesAlertRead(d *pluginsdk.ResourceData, meta d.Set("location", azure.NormalizeLocation(*location)) } + d.Set("auto_mitigate", resp.AutoMitigate) d.Set("description", resp.Description) if resp.Enabled == insights.EnabledTrue { d.Set("enabled", true) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 98486ab82878..942d0e6df0f8 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -125,6 +125,8 @@ QUERY action_group = [azurerm_monitor_action_group.test.id] } + auto_mitigate = false + trigger { operator = "GreaterThan" threshold = 5000 diff --git a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown index 8dfd8a7386e7..8b7592f56a41 100644 --- a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown +++ b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown @@ -143,6 +143,7 @@ The following arguments are supported: * `trigger` - (Required) The condition that results in the alert rule being run. * `action` - (Required) An `action` block as defined below. * `authorized_resource_ids` - (Optional) List of Resource IDs referred into query. +* `auto_mitigate` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `true`. * `description` - (Optional) The description of the scheduled query rule. * `enabled` - (Optional) Whether this scheduled query rule is enabled. Default is `true`. * `severity` - (Optional) Severity of the alert. Possible values include: 0, 1, 2, 3, or 4. From 47864d59dd049cf32c947882cd2c72b9353e972a Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 1 Sep 2021 17:02:16 -0400 Subject: [PATCH 02/18] fix lint --- .../monitor_scheduled_query_rules_alert_resource_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 942d0e6df0f8..6db4b6431065 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -118,15 +118,14 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "test" { QUERY - frequency = 60 - time_window = 60 + frequency = 60 + time_window = 60 + auto_mitigate = false action { action_group = [azurerm_monitor_action_group.test.id] } - auto_mitigate = false - trigger { operator = "GreaterThan" threshold = 5000 From 64f5c733efe1a13f8d5ed45b141d5709162c1dfc Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Thu, 2 Sep 2021 09:14:36 -0400 Subject: [PATCH 03/18] change tests --- .../monitor_scheduled_query_rules_alert_resource_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 6db4b6431065..048c13ea5634 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -120,7 +120,6 @@ QUERY frequency = 60 time_window = 60 - auto_mitigate = false action { action_group = [azurerm_monitor_action_group.test.id] @@ -219,8 +218,9 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "test" { frequency = 60 time_window = 60 - severity = 3 - throttling = 5 + severity = 3 + throttling = 5 + auto_mitigate = false action { action_group = [azurerm_monitor_action_group.test.id] email_subject = "Custom alert email subject" From f55890cf8e1901f1d66522ec41480a116bc98141 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Thu, 2 Sep 2021 09:43:58 -0400 Subject: [PATCH 04/18] add auto_mitigate and throttle exclusion --- ...or_scheduled_query_rules_alert_resource.go | 4 ++ ...heduled_query_rules_alert_resource_test.go | 65 ++++++++++++++++++- ..._scheduled_query_rules_alert.html.markdown | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index 963897903317..c2272551ee61 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -220,6 +220,10 @@ func resourceMonitorScheduledQueryRulesAlertCreateUpdate(d *pluginsdk.ResourceDa if timeWindow < frequency { return fmt.Errorf("in parameter values for Scheduled Query Rules %q (Resource Group %q): time_window must be greater than or equal to frequency", name, resourceGroup) } + throttling := d.Get("throttling").(int) + if !d.Get("auto_mitigate").(bool) && throttling > 0 { + return fmt.Errorf("in parameter values for Scheduled Query Rules %q (Resource Group %q): Only one of `auto_resolve` or `throttling` can be set", name, resourceGroup) + } query := d.Get("query").(string) _, ok := d.GetOk("metric_trigger") diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 048c13ea5634..e56f58b09c17 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -3,6 +3,7 @@ package monitor_test import ( "context" "fmt" + "regexp" "testing" "time" @@ -86,6 +87,68 @@ func TestAccMonitorScheduledQueryRules_AlertingActionCrossResource(t *testing.T) }) } +func TestAccApplicationGateway_backendHttpSettingsHostNameAndPick(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_monitor_scheduled_query_rules_alert", "test") + r := MonitorScheduledQueryRulesResource{} + ts := time.Now().Format(time.RFC3339) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.AlertingActionBadConfig(data, ts), + ExpectError: regexp.MustCompile("Only one of `auto_resolve` or `throttling` can be set"), + }, + }) +} + +func (MonitorScheduledQueryRulesResource) AlertingActionBadConfig(data acceptance.TestData, ts string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-monitor-%d" + location = "%s" +} + +resource "azurerm_application_insights" "test" { + name = "acctestAppInsights-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + application_type = "web" +} + +resource "azurerm_monitor_action_group" "test" { + name = "acctestActionGroup-%d" + resource_group_name = azurerm_resource_group.test.name + short_name = "acctestag" +} + +resource "azurerm_monitor_scheduled_query_rules_alert" "test" { + name = "acctestsqr-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + data_source_id = azurerm_application_insights.test.id + query = <<-QUERY + let d=datatable(TimeGenerated: datetime, usage_percent: double) [ '%s', 25.4, '%s', 75.4 ]; + d | summarize AggregatedValue=avg(usage_percent) by bin(TimeGenerated, 1h) +QUERY + + + frequency = 60 + time_window = 60 + throttling = 5 + auto_mitigate = true + + action { + action_group = [azurerm_monitor_action_group.test.id] + } + + trigger { + operator = "GreaterThan" + threshold = 5000 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, ts, ts) +} + func (MonitorScheduledQueryRulesResource) AlertingActionConfigBasic(data acceptance.TestData, ts string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -220,7 +283,7 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "test" { severity = 3 throttling = 5 - auto_mitigate = false + action { action_group = [azurerm_monitor_action_group.test.id] email_subject = "Custom alert email subject" diff --git a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown index 8b7592f56a41..94981ea197e2 100644 --- a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown +++ b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown @@ -144,6 +144,7 @@ The following arguments are supported: * `action` - (Required) An `action` block as defined below. * `authorized_resource_ids` - (Optional) List of Resource IDs referred into query. * `auto_mitigate` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `true`. +-> **NOTE** The `auto_mitigate` and `throttling` are mutually exclusive and cannot both be set. * `description` - (Optional) The description of the scheduled query rule. * `enabled` - (Optional) Whether this scheduled query rule is enabled. Default is `true`. * `severity` - (Optional) Severity of the alert. Possible values include: 0, 1, 2, 3, or 4. From 25b763605ab0bfb9f26a8ada1905c86a19c9c765 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Thu, 2 Sep 2021 10:07:50 -0400 Subject: [PATCH 05/18] fix lint --- .../monitor_scheduled_query_rules_alert_resource_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index e56f58b09c17..542e11d97dea 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -181,8 +181,8 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "test" { QUERY - frequency = 60 - time_window = 60 + frequency = 60 + time_window = 60 action { action_group = [azurerm_monitor_action_group.test.id] @@ -281,8 +281,8 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "test" { frequency = 60 time_window = 60 - severity = 3 - throttling = 5 + severity = 3 + throttling = 5 action { action_group = [azurerm_monitor_action_group.test.id] From b931924bc9fa3759e2dcae9395f861e4f4923f84 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Thu, 2 Sep 2021 10:21:33 -0400 Subject: [PATCH 06/18] fixes --- .../monitor/monitor_scheduled_query_rules_alert_resource.go | 4 ++-- .../monitor_scheduled_query_rules_alert_resource_test.go | 4 ++-- .../docs/r/monitor_scheduled_query_rules_alert.html.markdown | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index c2272551ee61..705d27c38659 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -95,7 +95,7 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { "auto_mitigate": { Type: pluginsdk.TypeBool, Optional: true, - Default: true, + Default: false, }, "description": { Type: pluginsdk.TypeString, @@ -222,7 +222,7 @@ func resourceMonitorScheduledQueryRulesAlertCreateUpdate(d *pluginsdk.ResourceDa } throttling := d.Get("throttling").(int) if !d.Get("auto_mitigate").(bool) && throttling > 0 { - return fmt.Errorf("in parameter values for Scheduled Query Rules %q (Resource Group %q): Only one of `auto_resolve` or `throttling` can be set", name, resourceGroup) + return fmt.Errorf("in parameter values for Scheduled Query Rules %q (Resource Group %q): Only one of `auto_mitigate` or `throttling` can be set", name, resourceGroup) } query := d.Get("query").(string) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 542e11d97dea..52c3e90af8c1 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -87,7 +87,7 @@ func TestAccMonitorScheduledQueryRules_AlertingActionCrossResource(t *testing.T) }) } -func TestAccApplicationGateway_backendHttpSettingsHostNameAndPick(t *testing.T) { +func TestAccMonitorScheduledQueryRules_AutoResolveAndThrottling(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_monitor_scheduled_query_rules_alert", "test") r := MonitorScheduledQueryRulesResource{} ts := time.Now().Format(time.RFC3339) @@ -95,7 +95,7 @@ func TestAccApplicationGateway_backendHttpSettingsHostNameAndPick(t *testing.T) data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.AlertingActionBadConfig(data, ts), - ExpectError: regexp.MustCompile("Only one of `auto_resolve` or `throttling` can be set"), + ExpectError: regexp.MustCompile("Only one of `auto_mitigate` or `throttling` can be set"), }, }) } diff --git a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown index 94981ea197e2..95ec56197d84 100644 --- a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown +++ b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown @@ -143,7 +143,7 @@ The following arguments are supported: * `trigger` - (Required) The condition that results in the alert rule being run. * `action` - (Required) An `action` block as defined below. * `authorized_resource_ids` - (Optional) List of Resource IDs referred into query. -* `auto_mitigate` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `true`. +* `auto_mitigate` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `false`. -> **NOTE** The `auto_mitigate` and `throttling` are mutually exclusive and cannot both be set. * `description` - (Optional) The description of the scheduled query rule. * `enabled` - (Optional) Whether this scheduled query rule is enabled. Default is `true`. From eb2c5e8c45978537e7d32a2f12494ee5b6148994 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Thu, 2 Sep 2021 10:23:22 -0400 Subject: [PATCH 07/18] fix validation --- .../monitor/monitor_scheduled_query_rules_alert_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index 705d27c38659..f1aba1b9a35e 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -221,7 +221,7 @@ func resourceMonitorScheduledQueryRulesAlertCreateUpdate(d *pluginsdk.ResourceDa return fmt.Errorf("in parameter values for Scheduled Query Rules %q (Resource Group %q): time_window must be greater than or equal to frequency", name, resourceGroup) } throttling := d.Get("throttling").(int) - if !d.Get("auto_mitigate").(bool) && throttling > 0 { + if d.Get("auto_mitigate").(bool) && throttling > 0 { return fmt.Errorf("in parameter values for Scheduled Query Rules %q (Resource Group %q): Only one of `auto_mitigate` or `throttling` can be set", name, resourceGroup) } From 83e3c04420c4013b9d362ce82e0d127be6f4d5ec Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Tue, 7 Sep 2021 11:32:17 -0400 Subject: [PATCH 08/18] changes from feedback --- ...or_scheduled_query_rules_alert_resource.go | 18 +++--- ...heduled_query_rules_alert_resource_test.go | 63 ------------------- ..._scheduled_query_rules_alert.html.markdown | 2 +- 3 files changed, 9 insertions(+), 74 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index f1aba1b9a35e..073d28e10c17 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -93,9 +93,10 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { ValidateFunc: azure.ValidateResourceID, }, "auto_mitigate": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + ConflictsWith: []string{"throttle"}, }, "description": { Type: pluginsdk.TypeString, @@ -131,9 +132,10 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { ValidateFunc: validation.IntBetween(0, 4), }, "throttling": { - Type: pluginsdk.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(0, 10000), + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 10000), + ConflictsWith: []string{"auto_mitigate"}, }, "time_window": { Type: pluginsdk.TypeInt, @@ -220,10 +222,6 @@ func resourceMonitorScheduledQueryRulesAlertCreateUpdate(d *pluginsdk.ResourceDa if timeWindow < frequency { return fmt.Errorf("in parameter values for Scheduled Query Rules %q (Resource Group %q): time_window must be greater than or equal to frequency", name, resourceGroup) } - throttling := d.Get("throttling").(int) - if d.Get("auto_mitigate").(bool) && throttling > 0 { - return fmt.Errorf("in parameter values for Scheduled Query Rules %q (Resource Group %q): Only one of `auto_mitigate` or `throttling` can be set", name, resourceGroup) - } query := d.Get("query").(string) _, ok := d.GetOk("metric_trigger") diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 52c3e90af8c1..325946c74a66 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -3,7 +3,6 @@ package monitor_test import ( "context" "fmt" - "regexp" "testing" "time" @@ -87,68 +86,6 @@ func TestAccMonitorScheduledQueryRules_AlertingActionCrossResource(t *testing.T) }) } -func TestAccMonitorScheduledQueryRules_AutoResolveAndThrottling(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_monitor_scheduled_query_rules_alert", "test") - r := MonitorScheduledQueryRulesResource{} - ts := time.Now().Format(time.RFC3339) - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.AlertingActionBadConfig(data, ts), - ExpectError: regexp.MustCompile("Only one of `auto_mitigate` or `throttling` can be set"), - }, - }) -} - -func (MonitorScheduledQueryRulesResource) AlertingActionBadConfig(data acceptance.TestData, ts string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-monitor-%d" - location = "%s" -} - -resource "azurerm_application_insights" "test" { - name = "acctestAppInsights-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - application_type = "web" -} - -resource "azurerm_monitor_action_group" "test" { - name = "acctestActionGroup-%d" - resource_group_name = azurerm_resource_group.test.name - short_name = "acctestag" -} - -resource "azurerm_monitor_scheduled_query_rules_alert" "test" { - name = "acctestsqr-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - data_source_id = azurerm_application_insights.test.id - query = <<-QUERY - let d=datatable(TimeGenerated: datetime, usage_percent: double) [ '%s', 25.4, '%s', 75.4 ]; - d | summarize AggregatedValue=avg(usage_percent) by bin(TimeGenerated, 1h) -QUERY - - - frequency = 60 - time_window = 60 - throttling = 5 - auto_mitigate = true - - action { - action_group = [azurerm_monitor_action_group.test.id] - } - - trigger { - operator = "GreaterThan" - threshold = 5000 - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, ts, ts) -} - func (MonitorScheduledQueryRulesResource) AlertingActionConfigBasic(data acceptance.TestData, ts string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { diff --git a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown index 95ec56197d84..94981ea197e2 100644 --- a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown +++ b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown @@ -143,7 +143,7 @@ The following arguments are supported: * `trigger` - (Required) The condition that results in the alert rule being run. * `action` - (Required) An `action` block as defined below. * `authorized_resource_ids` - (Optional) List of Resource IDs referred into query. -* `auto_mitigate` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `false`. +* `auto_mitigate` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `true`. -> **NOTE** The `auto_mitigate` and `throttling` are mutually exclusive and cannot both be set. * `description` - (Optional) The description of the scheduled query rule. * `enabled` - (Optional) Whether this scheduled query rule is enabled. Default is `true`. From bf33fce101086846587047c13ac19b66a182910f Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Tue, 7 Sep 2021 11:50:51 -0400 Subject: [PATCH 09/18] fix test --- .../monitor/monitor_scheduled_query_rules_alert_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index 073d28e10c17..d32df53f8b39 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -96,7 +96,7 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { Type: pluginsdk.TypeBool, Optional: true, Default: true, - ConflictsWith: []string{"throttle"}, + ConflictsWith: []string{"throttling"}, }, "description": { Type: pluginsdk.TypeString, From a904a90932013419bdf19d8a96e9e5a8cdf80642 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 8 Sep 2021 09:38:20 -0400 Subject: [PATCH 10/18] changes from feedback --- ...or_scheduled_query_rules_alert_resource.go | 8 +- ...heduled_query_rules_alert_resource_test.go | 78 +++++++++++++++++++ 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index d32df53f8b39..1ed05c03ff63 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -92,7 +92,7 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { Required: true, ValidateFunc: azure.ValidateResourceID, }, - "auto_mitigate": { + "auto_mitigation_enabled": { Type: pluginsdk.TypeBool, Optional: true, Default: true, @@ -135,7 +135,7 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { Type: pluginsdk.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(0, 10000), - ConflictsWith: []string{"auto_mitigate"}, + ConflictsWith: []string{"auto_mitigation_enabled"}, }, "time_window": { Type: pluginsdk.TypeInt, @@ -246,7 +246,7 @@ func resourceMonitorScheduledQueryRulesAlertCreateUpdate(d *pluginsdk.ResourceDa } } - autoMitigate := d.Get("auto_mitigate").(bool) + autoMitigate := d.Get("auto_mitigation_enabled").(bool) description := d.Get("description").(string) enabledRaw := d.Get("enabled").(bool) @@ -319,7 +319,7 @@ func resourceMonitorScheduledQueryRulesAlertRead(d *pluginsdk.ResourceData, meta d.Set("location", azure.NormalizeLocation(*location)) } - d.Set("auto_mitigate", resp.AutoMitigate) + d.Set("auto_mitigation_enabled", resp.AutoMitigate) d.Set("description", resp.Description) if resp.Enabled == insights.EnabledTrue { d.Set("enabled", true) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 325946c74a66..57d06b8f4fef 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -3,6 +3,7 @@ package monitor_test import ( "context" "fmt" + "strconv" "testing" "time" @@ -85,6 +86,83 @@ func TestAccMonitorScheduledQueryRules_AlertingActionCrossResource(t *testing.T) data.ImportStep(), }) } +func TestAccMonitorScheduledQueryRules_AutoMitigate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_monitor_scheduled_query_rules_alert", "test") + r := MonitorScheduledQueryRulesResource{} + ts := time.Now().Format(time.RFC3339) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.AlertingActionAutoMitigate(data, ts, 0, false), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.AlertingActionAutoMitigate(data, ts, 50, true), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.AlertingActionAutoMitigate(data, ts, 50, false), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.AlertingActionAutoMitigate(data, ts, 0, true), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (MonitorScheduledQueryRulesResource) AlertingActionAutoMitigate(data acceptance.TestData, ts string, throttling int, autoMitigate bool) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-monitor-%d" + location = "%s" +} +resource "azurerm_application_insights" "test" { + name = "acctestAppInsights-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + application_type = "web" +} +resource "azurerm_monitor_action_group" "test" { + name = "acctestActionGroup-%d" + resource_group_name = azurerm_resource_group.test.name + short_name = "acctestag" +} +resource "azurerm_monitor_scheduled_query_rules_alert" "test" { + name = "acctestsqr-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + data_source_id = azurerm_application_insights.test.id + query = <<-QUERY + let d=datatable(TimeGenerated: datetime, usage_percent: double) [ '%s', 25.4, '%s', 75.4 ]; + d | summarize AggregatedValue=avg(usage_percent) by bin(TimeGenerated, 1h) +QUERY + frequency = 60 + time_window = 60 + throttling = %d + auto_mitigate_enabled = %s + action { + action_group = [azurerm_monitor_action_group.test.id] + } + trigger { + operator = "GreaterThan" + threshold = 5000 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, ts, ts, throttling, strconv.FormatBool(autoMitigate)) +} func (MonitorScheduledQueryRulesResource) AlertingActionConfigBasic(data acceptance.TestData, ts string) string { return fmt.Sprintf(` From a631c544a2a7c1ea98f9f09705ee61bd882c8601 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 8 Sep 2021 09:42:04 -0400 Subject: [PATCH 11/18] fix doc --- .../docs/r/monitor_scheduled_query_rules_alert.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown index 94981ea197e2..4db411566169 100644 --- a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown +++ b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown @@ -143,8 +143,8 @@ The following arguments are supported: * `trigger` - (Required) The condition that results in the alert rule being run. * `action` - (Required) An `action` block as defined below. * `authorized_resource_ids` - (Optional) List of Resource IDs referred into query. -* `auto_mitigate` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `true`. --> **NOTE** The `auto_mitigate` and `throttling` are mutually exclusive and cannot both be set. +* `auto_mitigate_enabled` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `true`. +-> **NOTE** The `auto_mitigate_enabled` and `throttling` are mutually exclusive and cannot both be set. * `description` - (Optional) The description of the scheduled query rule. * `enabled` - (Optional) Whether this scheduled query rule is enabled. Default is `true`. * `severity` - (Optional) Severity of the alert. Possible values include: 0, 1, 2, 3, or 4. From 9bf7c46629aa1e366d0030d8e2f043a5e7aac7dd Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 8 Sep 2021 10:53:07 -0400 Subject: [PATCH 12/18] changed test --- ...cheduled_query_rules_alert_resource_test.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 57d06b8f4fef..bbe842b865a3 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -93,28 +93,21 @@ func TestAccMonitorScheduledQueryRules_AutoMitigate(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.AlertingActionAutoMitigate(data, ts, 0, false), + Config: r.AlertingActionAutoMitigate(data, ts, false), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.AlertingActionAutoMitigate(data, ts, 50, true), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - { - Config: r.AlertingActionAutoMitigate(data, ts, 50, false), + Config: r.AlertingActionConfigComplete(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.AlertingActionAutoMitigate(data, ts, 0, true), + Config: r.AlertingActionAutoMitigate(data, ts, true), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -123,7 +116,7 @@ func TestAccMonitorScheduledQueryRules_AutoMitigate(t *testing.T) { }) } -func (MonitorScheduledQueryRulesResource) AlertingActionAutoMitigate(data acceptance.TestData, ts string, throttling int, autoMitigate bool) string { +func (MonitorScheduledQueryRulesResource) AlertingActionAutoMitigate(data acceptance.TestData, ts string, autoMitigate bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-monitor-%d" @@ -151,7 +144,6 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "test" { QUERY frequency = 60 time_window = 60 - throttling = %d auto_mitigate_enabled = %s action { action_group = [azurerm_monitor_action_group.test.id] @@ -161,7 +153,7 @@ QUERY threshold = 5000 } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, ts, ts, throttling, strconv.FormatBool(autoMitigate)) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, ts, ts, strconv.FormatBool(autoMitigate)) } func (MonitorScheduledQueryRulesResource) AlertingActionConfigBasic(data acceptance.TestData, ts string) string { From 3c973c6b90f268311a4531d93c5d0c389812baea Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 8 Sep 2021 11:36:03 -0400 Subject: [PATCH 13/18] fix lint --- ...onitor_scheduled_query_rules_alert_resource_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index bbe842b865a3..413433b6f116 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -134,11 +134,11 @@ resource "azurerm_monitor_action_group" "test" { short_name = "acctestag" } resource "azurerm_monitor_scheduled_query_rules_alert" "test" { - name = "acctestsqr-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - data_source_id = azurerm_application_insights.test.id - query = <<-QUERY + name = "acctestsqr-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + data_source_id = azurerm_application_insights.test.id + query = <<-QUERY let d=datatable(TimeGenerated: datetime, usage_percent: double) [ '%s', 25.4, '%s', 75.4 ]; d | summarize AggregatedValue=avg(usage_percent) by bin(TimeGenerated, 1h) QUERY From 9557bb690c0842204e8d3c4d118f91dd6f83013a Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 8 Sep 2021 13:45:21 -0400 Subject: [PATCH 14/18] don't send throttling if not set --- ...nitor_scheduled_query_rules_alert_resource.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index 1ed05c03ff63..9578060e174e 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -134,6 +134,7 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { "throttling": { Type: pluginsdk.TypeInt, Optional: true, + Default: nil, ValidateFunc: validation.IntBetween(0, 10000), ConflictsWith: []string{"auto_mitigation_enabled"}, }, @@ -395,17 +396,20 @@ func expandMonitorScheduledQueryRulesAlertingAction(d *pluginsdk.ResourceData) * alertAction := expandMonitorScheduledQueryRulesAlertAction(alertActionRaw) severityRaw := d.Get("severity").(int) severity := strconv.Itoa(severityRaw) - throttling := d.Get("throttling").(int) + throttling, throttlingOk := d.GetOk("throttling") triggerRaw := d.Get("trigger").([]interface{}) trigger := expandMonitorScheduledQueryRulesAlertTrigger(triggerRaw) action := insights.AlertingAction{ - AznsAction: alertAction, - Severity: insights.AlertSeverity(severity), - ThrottlingInMin: utils.Int32(int32(throttling)), - Trigger: trigger, - OdataType: insights.OdataTypeBasicActionOdataTypeMicrosoftWindowsAzureManagementMonitoringAlertsModelsMicrosoftAppInsightsNexusDataContractsResourcesScheduledQueryRulesAlertingAction, + AznsAction: alertAction, + Severity: insights.AlertSeverity(severity), + Trigger: trigger, + OdataType: insights.OdataTypeBasicActionOdataTypeMicrosoftWindowsAzureManagementMonitoringAlertsModelsMicrosoftAppInsightsNexusDataContractsResourcesScheduledQueryRulesAlertingAction, + } + + if throttlingOk { + action.ThrottlingInMin = utils.Int32(int32(throttling.(int))) } return &action From aabf47b2e2ce7774d9f285a5e14089db0ea852c7 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 15 Sep 2021 09:15:03 -0400 Subject: [PATCH 15/18] Apply suggestions from code review Co-authored-by: stephybun --- .../monitor_scheduled_query_rules_alert_resource.go | 9 +++++---- .../monitor_scheduled_query_rules_alert_resource_test.go | 2 +- .../r/monitor_scheduled_query_rules_alert.html.markdown | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index 9578060e174e..5c074890fb89 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -95,7 +95,7 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { "auto_mitigation_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: true, + Default: false ConflictsWith: []string{"throttling"}, }, "description": { @@ -134,7 +134,6 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { "throttling": { Type: pluginsdk.TypeInt, Optional: true, - Default: nil, ValidateFunc: validation.IntBetween(0, 10000), ConflictsWith: []string{"auto_mitigation_enabled"}, }, @@ -271,7 +270,7 @@ func resourceMonitorScheduledQueryRulesAlertCreateUpdate(d *pluginsdk.ResourceDa Source: source, Schedule: schedule, Action: action, - AutoMitigate: &autoMitigate, + AutoMitigate: utils.Bool(autoMitigate), }, Tags: expandedTags, } @@ -408,7 +407,9 @@ func expandMonitorScheduledQueryRulesAlertingAction(d *pluginsdk.ResourceData) * OdataType: insights.OdataTypeBasicActionOdataTypeMicrosoftWindowsAzureManagementMonitoringAlertsModelsMicrosoftAppInsightsNexusDataContractsResourcesScheduledQueryRulesAlertingAction, } - if throttlingOk { + if throttling, ok := d.Get("throttling").(int); ok && throttling != 0 { + action.ThrottlingInMin = utils.Int32(int32(throttling)) + } action.ThrottlingInMin = utils.Int32(int32(throttling.(int))) } diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 413433b6f116..9deb68ea7a30 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -144,7 +144,7 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "test" { QUERY frequency = 60 time_window = 60 - auto_mitigate_enabled = %s + auto_mitigation_enabled = %s action { action_group = [azurerm_monitor_action_group.test.id] } diff --git a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown index 4db411566169..dfdcc47586e8 100644 --- a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown +++ b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown @@ -143,8 +143,8 @@ The following arguments are supported: * `trigger` - (Required) The condition that results in the alert rule being run. * `action` - (Required) An `action` block as defined below. * `authorized_resource_ids` - (Optional) List of Resource IDs referred into query. -* `auto_mitigate_enabled` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `true`. --> **NOTE** The `auto_mitigate_enabled` and `throttling` are mutually exclusive and cannot both be set. +* `auto_mitigation_enabled` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `false`. +-> **NOTE** The `auto_mitigation_enabled` and `throttling` are mutually exclusive and cannot both be set. * `description` - (Optional) The description of the scheduled query rule. * `enabled` - (Optional) Whether this scheduled query rule is enabled. Default is `true`. * `severity` - (Optional) Severity of the alert. Possible values include: 0, 1, 2, 3, or 4. From ad0c15ec810180dda420c54bf08948c079b1a3a3 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 15 Sep 2021 09:19:47 -0400 Subject: [PATCH 16/18] fix bad github apply --- .../monitor/monitor_scheduled_query_rules_alert_resource.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go index 5c074890fb89..ded39cbf361f 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource.go @@ -95,7 +95,7 @@ func resourceMonitorScheduledQueryRulesAlert() *pluginsdk.Resource { "auto_mitigation_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: false + Default: false, ConflictsWith: []string{"throttling"}, }, "description": { @@ -395,7 +395,6 @@ func expandMonitorScheduledQueryRulesAlertingAction(d *pluginsdk.ResourceData) * alertAction := expandMonitorScheduledQueryRulesAlertAction(alertActionRaw) severityRaw := d.Get("severity").(int) severity := strconv.Itoa(severityRaw) - throttling, throttlingOk := d.GetOk("throttling") triggerRaw := d.Get("trigger").([]interface{}) trigger := expandMonitorScheduledQueryRulesAlertTrigger(triggerRaw) @@ -410,8 +409,6 @@ func expandMonitorScheduledQueryRulesAlertingAction(d *pluginsdk.ResourceData) * if throttling, ok := d.Get("throttling").(int); ok && throttling != 0 { action.ThrottlingInMin = utils.Int32(int32(throttling)) } - action.ThrottlingInMin = utils.Int32(int32(throttling.(int))) - } return &action } From 1fe0da238d0a4d3f21d189f633d0a7fac072ffcd Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Wed, 15 Sep 2021 09:31:19 -0400 Subject: [PATCH 17/18] fix tf linting --- ...or_scheduled_query_rules_alert_resource_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go index 9deb68ea7a30..6bdb64b5df7a 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_alert_resource_test.go @@ -134,16 +134,16 @@ resource "azurerm_monitor_action_group" "test" { short_name = "acctestag" } resource "azurerm_monitor_scheduled_query_rules_alert" "test" { - name = "acctestsqr-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - data_source_id = azurerm_application_insights.test.id - query = <<-QUERY + name = "acctestsqr-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + data_source_id = azurerm_application_insights.test.id + query = <<-QUERY let d=datatable(TimeGenerated: datetime, usage_percent: double) [ '%s', 25.4, '%s', 75.4 ]; d | summarize AggregatedValue=avg(usage_percent) by bin(TimeGenerated, 1h) QUERY - frequency = 60 - time_window = 60 + frequency = 60 + time_window = 60 auto_mitigation_enabled = %s action { action_group = [azurerm_monitor_action_group.test.id] From 77c78979b6110688e8a9a9669d85dd6f86c0225b Mon Sep 17 00:00:00 2001 From: stephybun Date: Wed, 15 Sep 2021 17:33:06 +0200 Subject: [PATCH 18/18] fix note in docs --- .../docs/r/monitor_scheduled_query_rules_alert.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown index dfdcc47586e8..b4456104939a 100644 --- a/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown +++ b/website/docs/r/monitor_scheduled_query_rules_alert.html.markdown @@ -144,7 +144,7 @@ The following arguments are supported: * `action` - (Required) An `action` block as defined below. * `authorized_resource_ids` - (Optional) List of Resource IDs referred into query. * `auto_mitigation_enabled` - (Optional) Should the alerts in this Metric Alert be auto resolved? Defaults to `false`. --> **NOTE** The `auto_mitigation_enabled` and `throttling` are mutually exclusive and cannot both be set. +-> **NOTE** `auto_mitigation_enabled` and `throttling` are mutually exclusive and cannot both be set. * `description` - (Optional) The description of the scheduled query rule. * `enabled` - (Optional) Whether this scheduled query rule is enabled. Default is `true`. * `severity` - (Optional) Severity of the alert. Possible values include: 0, 1, 2, 3, or 4.