Skip to content

Commit 6eb1f10

Browse files
committed
Disable exception alerting when service is disabled
If SERVICE_ENABLED is false we put up a maintenence page which is a 503 response. This is considered an exception so it sets off our app insights exception alert. Instead we can just not enable this alert in this situation, however the rest of the alerts are still enabled as the environment is still running regardless of whether the app is serving normal requests.
1 parent eece0b0 commit 6eb1f10

5 files changed

Lines changed: 16 additions & 6 deletions

File tree

infrastructure/modules/container-apps/variables.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ variable "environment" {
6464
type = string
6565
}
6666

67+
variable "env_vars_from_yaml" {
68+
type = map(any)
69+
}
70+
6771
variable "fetch_secrets_from_app_key_vault" {
6872
description = <<EOT
6973
Set to false initially to create and populate the app key vault.
@@ -215,12 +219,9 @@ locals {
215219
database_name = "manage_breast_screening"
216220
# Here we expect the environment to be in format pr-XXX. For example PR 1234 would have environment pr-1234 and port 2234
217221
database_port = var.deploy_database_as_container ? try(tonumber(regex("\\d+", var.environment)), 24) + 1000 : 5432
218-
env_vars_from_yaml = yamldecode(
219-
file("${path.module}/../../environments/${var.env_config}/variables.yml")
220-
)
221-
external_url = "https://${module.frontdoor_endpoint.custom_domains["${var.environment}-domain"].host_name}/"
222+
external_url = "https://${module.frontdoor_endpoint.custom_domains["${var.environment}-domain"].host_name}/"
222223
common_env = merge(
223-
local.env_vars_from_yaml,
224+
var.env_vars_from_yaml,
224225
{
225226
SSL_MODE = "require"
226227
DJANGO_ENV = var.env_config

infrastructure/modules/infra/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module "app_insights_audit" {
8080
log_analytics_workspace_id = module.log_analytics_workspace_audit.id
8181

8282
action_group_id = module.monitor_action_group.monitor_action_group.id
83-
enable_alerting = var.enable_alerting
83+
enable_alerting = var.enable_alerting && try(var.env_vars_from_yaml["SERVICE_ENABLED"], true)
8484
}
8585

8686
module "private_link_scoped_service_law" {

infrastructure/modules/infra/variables.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ variable "environment" {
88
type = string
99
}
1010

11+
variable "env_vars_from_yaml" {
12+
type = map(any)
13+
}
1114
variable "resource_group_name" {
1215
description = "Infra resource group name"
1316
type = string

infrastructure/terraform/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module "infra" {
1414
infra_key_vault_rg = local.infra_key_vault_rg
1515
app_short_name = var.app_short_name
1616
environment = var.env_config
17+
env_vars_from_yaml = local.env_vars_from_yaml
1718
hub = var.hub
1819
protect_keyvault = var.protect_keyvault
1920
vnet_address_space = var.vnet_address_space
@@ -60,6 +61,7 @@ module "container-apps" {
6061
enable_entra_id_authentication = var.enable_entra_id_authentication
6162
environment = var.environment
6263
env_config = var.env_config
64+
env_vars_from_yaml = local.env_vars_from_yaml
6365
fetch_secrets_from_app_key_vault = var.fetch_secrets_from_app_key_vault
6466
deploy_infra = var.deploy_infra
6567
front_door_profile = var.front_door_profile

infrastructure/terraform/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,8 @@ locals {
210210
resource_group_name = "rg-${var.app_short_name}-${var.env_config}-uks"
211211
infra_key_vault_name = "kv-${var.app_short_name}-${var.env_config}-inf"
212212
infra_key_vault_rg = "rg-${var.app_short_name}-${var.env_config}-infra"
213+
214+
env_vars_from_yaml = yamldecode(
215+
file("${path.module}/../environments/${var.env_config}/variables.yml")
216+
)
213217
}

0 commit comments

Comments
 (0)