Skip to content

Commit 1513a12

Browse files
committed
DTOSS-00000: Add alerting availability test
The application insights web availability test was firing but it was not firing the alert to the email group because the azurerm_monitor_metric_alert resource was missing. This simply adds this alert into the child module.
1 parent eb187eb commit 1513a12

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

infrastructure/modules/application-insights-availability-test/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ See also the following ADO template step that can be used to verify endpoint hea
1212
For the list of inputs, outputs, resources... check the [terraform module documentation](tfdocs.md).
1313

1414
## Usage
15-
Create the application Insights availability test:
15+
Create the application insights availability test:
1616
```hcl
1717
module "azurerm_application_insights_standard_web_test" {
1818
source = "../dtos-devops-templates/infrastructure/modules/application-insights-availability-test"
1919
2020
name = "${var.app_short_name}-web-${var.environment}"
2121
resource_group_name = var.resource_group_name_infra
22-
application_insights_id = data.azurerm_log_analytics_workspace.audit[0].id
23-
target_url = "${module.container-apps[0].external_url}healthcheck/"
22+
action_group_id = module.monitor_action_group.id
23+
application_insights_id = module.log_analytics_workspace_audit.id
24+
target_url = "${module.container-apps[0].external_url}healthcheck"
2425
}
2526
```

infrastructure/modules/application-insights-availability-test/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,21 @@ resource "azurerm_application_insights_standard_web_test" "this" {
1414

1515
geo_locations = var.geo_locations
1616
}
17+
18+
resource "azurerm_monitor_metric_alert" "this" {
19+
name = "${var.name}-availability-alert"
20+
resource_group_name = var.resource_group_name
21+
scopes = [azurerm_application_insights_standard_web_test.this.id, var.application_insights_id]
22+
description = "availability test alert"
23+
severity = 0
24+
25+
application_insights_web_test_location_availability_criteria {
26+
web_test_id = azurerm_application_insights_standard_web_test.this.id
27+
component_id = var.application_insights_id
28+
failed_location_count = 2
29+
}
30+
31+
action {
32+
action_group_id = var.action_group_id
33+
}
34+
}

infrastructure/modules/application-insights-availability-test/tfdocs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
The following input variables are required:
66

7+
### <a name="input_action_group_id"></a> [action\_group\_id](#input\_action\_group\_id)
8+
9+
Description: ID of the action group to notify.
10+
11+
Type: `string`
12+
713
### <a name="input_application_insights_id"></a> [application\_insights\_id](#input\_application\_insights\_id)
814

915
Description: The Application Insights resource id to associate the availability test with
@@ -78,3 +84,4 @@ Default: `30`
7884
The following resources are used by this module:
7985

8086
- [azurerm_application_insights_standard_web_test.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights_standard_web_test) (resource)
87+
- [azurerm_monitor_metric_alert.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_metric_alert) (resource)

infrastructure/modules/application-insights-availability-test/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ variable "application_insights_id" {
2323
description = "The Application Insights resource id to associate the availability test with"
2424
}
2525

26+
variable "action_group_id" {
27+
type = string
28+
description = "ID of the action group to notify."
29+
}
30+
2631
variable "frequency" {
2732
type = number
2833
default = 300

0 commit comments

Comments
 (0)