Skip to content

Commit e95981c

Browse files
authored
Move monitoring config out of service root module (#884)
- Create new env-config object monitoring_config defined in monitoring.tf - Move incident_management_service_integration config to monitoring_config as incident_management_service attribute - Rename email_alerts_subscription_list to email_alert_recipients
1 parent 4d6247b commit e95981c

File tree

6 files changed

+33
-28
lines changed

6 files changed

+33
-28
lines changed

docs/infra/set-up-monitoring-alerts.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@
44

55
The monitoring module defines metric-based alerting policies that provide awareness into issues with the cloud application. The module supports integration with external incident management tools like Splunk-On-Call or Pagerduty. It also supports email alerts.
66

7-
### Set up email alerts.
8-
9-
1. Add the `email_alerts_subscription_list` variable to the monitoring module call in the service layer
10-
11-
For example:
12-
```
13-
module "monitoring" {
14-
source = "../../modules/monitoring"
15-
email_alerts_subscription_list = ["email1@email.com", "email2@email.com"]
16-
...
17-
}
18-
```
7+
### Set up email alerts
8+
9+
The monitoring module supports a simple email-based alerting system that does not rely on an external incident management service.
10+
11+
1. Update the `email_alert_recipients` variable in `app-config/env-config/monitoring.tf`
12+
1913
2. Run `make infra-update-app-service APP_NAME=<APP_NAME> ENVIRONMENT=<ENVIRONMENT>` to apply the changes to each environment.
20-
When any of the alerts described by the module are triggered notification will be sent to all emails specified in the `email_alerts_subscription_list`
2114

22-
### Set up External incident management service integration.
15+
### Integrate with an incident management service
2316

2417
1. Set setting `has_incident_management_service = true` in app-config/main.tf
2518
2. Get the integration URL for the incident management service and store it in AWS SSM Parameter Store by running the following command for each environment:
26-
```
27-
make infra-configure-monitoring-secrets APP_NAME=<APP_NAME> ENVIRONMENT=<ENVIRONMENT> URL=<WEBHOOK_URL>
28-
```
19+
20+
```bash
21+
make infra-configure-monitoring-secrets APP_NAME=<APP_NAME> ENVIRONMENT=<ENVIRONMENT> URL=<WEBHOOK_URL>
22+
```
23+
2924
3. Run `make infra-update-app-service APP_NAME=<APP_NAME> ENVIRONMENT=<ENVIRONMENT>` to apply the changes to each environment.

infra/modules/monitoring/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ resource "aws_cloudwatch_metric_alarm" "high_app_response_time" {
6868
#email integration
6969

7070
resource "aws_sns_topic_subscription" "email_integration" {
71-
for_each = var.email_alerts_subscription_list
71+
for_each = var.email_alert_recipients
7272
topic_arn = aws_sns_topic.this.arn
7373
protocol = "email"
7474
endpoint = each.value

infra/modules/monitoring/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
variable "email_alerts_subscription_list" {
1+
variable "email_alert_recipients" {
22
type = set(string)
33
default = []
44
description = "List of emails to subscribe to alerts"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
locals {
2+
monitoring_config = {
3+
# Emails to notify for alerts.
4+
# Use this as a simple notification mechanism if you don't have an incident management service.
5+
email_alert_recipients = []
6+
7+
incident_management_service = var.has_incident_management_service ? {
8+
integration_url_param_name = "/monitoring/${var.app_name}/${var.environment}/incident-management-integration-url"
9+
} : null
10+
}
11+
}
12+

infra/{{app_name}}/app-config/env-config/outputs.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ output "scheduled_jobs" {
1010
value = local.scheduled_jobs
1111
}
1212

13-
output "incident_management_service_integration" {
14-
value = var.has_incident_management_service ? {
15-
integration_url_param_name = "/monitoring/${var.app_name}/${var.environment}/incident-management-integration-url"
16-
} : null
13+
output "monitoring_config" {
14+
value = local.monitoring_config
1715
}
1816

1917
output "network_name" {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
locals {
2-
incident_management_service_integration_config = local.environment_config.incident_management_service_integration
2+
monitoring_config = local.environment_config.monitoring_config
3+
incident_management_service_integration_url = module.app_config.has_incident_management_service && !local.is_temporary ? data.aws_ssm_parameter.incident_management_service_integration_url[0].value : null
34
}
45

56
# Retrieve url for external incident management tool (e.g. Pagerduty, Splunk-On-Call)
67

78
data "aws_ssm_parameter" "incident_management_service_integration_url" {
89
count = module.app_config.has_incident_management_service ? 1 : 0
9-
name = local.incident_management_service_integration_config.integration_url_param_name
10+
name = local.monitoring_config.incident_management_service.integration_url_param_name
1011
}
1112

1213
module "monitoring" {
1314
source = "../../modules/monitoring"
14-
#Email subscription list:
15-
#email_alerts_subscription_list = ["email1@email.com", "email2@email.com"]
1615

1716
# Module takes service and ALB names to link all alerts with corresponding targets
1817
service_name = local.service_name
1918
load_balancer_arn_suffix = module.service.load_balancer_arn_suffix
20-
incident_management_service_integration_url = module.app_config.has_incident_management_service && !local.is_temporary ? data.aws_ssm_parameter.incident_management_service_integration_url[0].value : null
19+
email_alert_recipients = local.monitoring_config.email_alert_recipients
20+
incident_management_service_integration_url = local.incident_management_service_integration_url
2121
}

0 commit comments

Comments
 (0)