Skip to content

Commit 4d937ce

Browse files
authored
Merge pull request #1383 from NHSDigital/disable-5xx-alerts-when-environment-is-off
Disable exception alerting when service is disabled
2 parents 51a5046 + 6eb1f10 commit 4d937ce

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.
@@ -221,12 +225,9 @@ locals {
221225
database_name = "manage_breast_screening"
222226
# Here we expect the environment to be in format pr-XXX. For example PR 1234 would have environment pr-1234 and port 2234
223227
database_port = var.deploy_database_as_container ? try(tonumber(regex("\\d+", var.environment)), 24) + 1000 : 5432
224-
env_vars_from_yaml = yamldecode(
225-
file("${path.module}/../../environments/${var.env_config}/variables.yml")
226-
)
227-
external_url = "https://${module.frontdoor_endpoint.custom_domains["${var.environment}-domain"].host_name}/"
228+
external_url = "https://${module.frontdoor_endpoint.custom_domains["${var.environment}-domain"].host_name}/"
228229
common_env = merge(
229-
local.env_vars_from_yaml,
230+
var.env_vars_from_yaml,
230231
{
231232
SSL_MODE = "require"
232233
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)