Skip to content

Commit

Permalink
add test for authorized_resource_ids/tags (#16654)
Browse files Browse the repository at this point in the history
  • Loading branch information
shu-ying789 authored May 9, 2022
1 parent af0e34d commit 29f1f75
Showing 1 changed file with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down

0 comments on commit 29f1f75

Please sign in to comment.