From 29f1f752b5f5f73e56660ca6912b3005c660d31d Mon Sep 17 00:00:00 2001 From: shu-ying789 <96756505+shu-ying789@users.noreply.github.com> Date: Mon, 9 May 2022 16:17:13 +0800 Subject: [PATCH] add test for authorized_resource_ids/tags (#16654) --- ...scheduled_query_rules_log_resource_test.go | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/internal/services/monitor/monitor_scheduled_query_rules_log_resource_test.go b/internal/services/monitor/monitor_scheduled_query_rules_log_resource_test.go index 5aff4c544858..134130469762 100644 --- a/internal/services/monitor/monitor_scheduled_query_rules_log_resource_test.go +++ b/internal/services/monitor/monitor_scheduled_query_rules_log_resource_test.go @@ -140,32 +140,40 @@ resource "azurerm_monitor_scheduled_query_rules_log" "test" { func (MonitorScheduledQueryRulesLogResource) LogToMetricActionConfigComplete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-monitor-%d" - location = "%s" + name = "acctestRG-monitor-%[1]d" + location = "%[2]s" +} + +resource "azurerm_application_insights" "test" { + name = "acctestAppInsights-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + application_type = "web" } resource "azurerm_log_analytics_workspace" "test" { - name = "acctestWorkspace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctestWorkspace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" retention_in_days = 30 } resource "azurerm_monitor_action_group" "test" { - name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctestActionGroup-%[1]d" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" } resource "azurerm_monitor_scheduled_query_rules_log" "test" { - name = "acctestsqr-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + name = "acctestsqr-%[1]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location description = "test log to metric action" enabled = true - data_source_id = "${azurerm_log_analytics_workspace.test.id}" + data_source_id = azurerm_log_analytics_workspace.test.id + authorized_resource_ids = [azurerm_application_insights.test.id, azurerm_log_analytics_workspace.test.id] criteria { metric_name = "Average_%% Idle Time" @@ -175,27 +183,30 @@ resource "azurerm_monitor_scheduled_query_rules_log" "test" { values = ["*"] } } + tags = { + ENV = "test" + } } resource "azurerm_monitor_metric_alert" "test" { - name = "acctestmal-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - scopes = ["${azurerm_log_analytics_workspace.test.id}"] + name = "acctestmal-%[1]d" + resource_group_name = azurerm_resource_group.test.name + scopes = [azurerm_log_analytics_workspace.test.id] description = "Action will be triggered when Average %% Idle Time is less than 10." criteria { metric_namespace = "Microsoft.OperationalInsights/workspaces" - metric_name = "${azurerm_monitor_scheduled_query_rules_log.test.criteria[0].metric_name}" + metric_name = azurerm_monitor_scheduled_query_rules_log.test.criteria[0].metric_name aggregation = "Average" operator = "LessThan" threshold = 10 } action { - action_group_id = "${azurerm_monitor_action_group.test.id}" + action_group_id = azurerm_monitor_action_group.test.id } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary) } func (t MonitorScheduledQueryRulesLogResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {