Skip to content

Commit be9acee

Browse files
Add optional alarm trigger for PR env
1 parent f3370af commit be9acee

12 files changed

Lines changed: 21 additions & 2 deletions

infrastructure/terraform/components/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ No requirements.
1717
| <a name="input_core_environment"></a> [core\_environment](#input\_core\_environment) | Environment of Core | `string` | `"prod"` | no |
1818
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A map of default tags to apply to all taggable resources within the component | `map(string)` | `{}` | no |
1919
| <a name="input_disable_gateway_execute_endpoint"></a> [disable\_gateway\_execute\_endpoint](#input\_disable\_gateway\_execute\_endpoint) | Disable the execution endpoint for the API Gateway | `bool` | `true` | no |
20+
| <a name="input_enable_alarms_in_non_main"></a> [enable\_alarms\_in\_non\_main](#input\_enable\_alarms\_in\_non\_main) | Enable CloudWatch alarms in non-main environments (for example PR environments) | `bool` | `false` | no |
2021
| <a name="input_enable_api_data_trace"></a> [enable\_api\_data\_trace](#input\_enable\_api\_data\_trace) | Enable API Gateway data trace logging | `bool` | `false` | no |
2122
| <a name="input_enable_backups"></a> [enable\_backups](#input\_enable\_backups) | Enable backups | `bool` | `false` | no |
2223
| <a name="input_enable_event_cache"></a> [enable\_event\_cache](#input\_enable\_event\_cache) | Enable caching of events to an S3 bucket | `bool` | `true` | no |

infrastructure/terraform/components/api/cloudwatch_metric_alarm_apigw_5xx.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
resource "aws_cloudwatch_metric_alarm" "apigw_five_xx" {
2+
count = local.alarms_enabled ? 1 : 0
3+
24
alarm_name = "${local.csi}-apigw-5xx"
35
alarm_description = "RELIABILITY: API Gateway 5xx responses"
46

infrastructure/terraform/components/api/cloudwatch_metric_alarm_apigw_latency_anomaly.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
resource "aws_cloudwatch_metric_alarm" "apigw_latency_anomaly" {
2+
count = local.alarms_enabled ? 1 : 0
3+
24
alarm_name = "${local.csi}-apigw-latency-anomaly"
35
alarm_description = "RELIABILITY: API Gateway latency anomaly"
46
comparison_operator = "GreaterThanUpperThreshold"

infrastructure/terraform/components/api/cloudwatch_metric_alarm_apigw_latency_threshold.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
resource "aws_cloudwatch_metric_alarm" "apigw_latency_threshold" {
2+
count = local.alarms_enabled ? 1 : 0
3+
24
alarm_name = "${local.csi}-apigw-latency-threshold"
35
alarm_description = "RELIABILITY: API Gateway latency above threshold"
46

infrastructure/terraform/components/api/locals_alarms.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
locals {
2+
alarms_enabled = var.environment == "main" || var.enable_alarms_in_non_main
3+
24
apigw_alarm_dimensions = {
35
ApiName = aws_api_gateway_rest_api.main.name
46
Stage = aws_api_gateway_stage.main.stage_name

infrastructure/terraform/components/api/module_ddb_alarms_letter_queue.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "ddb_alarms_letter_queue" {
2+
count = local.alarms_enabled ? 1 : 0
23
source = "../../modules/alarms-ddb"
34
alarm_prefix = local.csi
45
table_name = aws_dynamodb_table.letter_queue.name

infrastructure/terraform/components/api/module_ddb_alarms_letters.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "ddb_alarms_letters" {
2+
count = local.alarms_enabled ? 1 : 0
23
source = "../../modules/alarms-ddb"
34
alarm_prefix = local.csi
45
table_name = aws_dynamodb_table.letters.name

infrastructure/terraform/components/api/module_ddb_alarms_mi.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "ddb_alarms_mi" {
2+
count = local.alarms_enabled ? 1 : 0
23
source = "../../modules/alarms-ddb"
34
alarm_prefix = local.csi
45
table_name = aws_dynamodb_table.mi.name

infrastructure/terraform/components/api/module_ddb_alarms_suppliers.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module "ddb_alarms_suppliers" {
2+
count = local.alarms_enabled ? 1 : 0
23
source = "../../modules/alarms-ddb"
34
alarm_prefix = local.csi
45
table_name = aws_dynamodb_table.suppliers.name

infrastructure/terraform/components/api/module_lambda_alarms.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "lambda_alarms" {
2-
for_each = local.lambda_alarm_targets
2+
for_each = local.alarms_enabled ? local.lambda_alarm_targets : {}
33
source = "../../modules/alarms-lambda"
44

55
alarm_prefix = local.csi

0 commit comments

Comments
 (0)