Skip to content

Commit 1904478

Browse files
committed
use key vault for monitoring email address
1 parent 7edf766 commit 1904478

File tree

10 files changed

+52
-27
lines changed

10 files changed

+52
-27
lines changed

infrastructure/environments/preprod/variables.tfvars

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ vnet_address_space = "10.10.0.0/16"
1212
nhs_notify_api_message_batch_url = "https://int.api.service.nhs.uk/comms/v1/message-batches"
1313
seed_demo_data = false
1414
allowed_paths = ["/notifications/message-status/create"]
15-
enable_monitoring = true
16-
monitoring_email_address = "[email protected]"
15+
enable_alerting = true

infrastructure/environments/review/variables.tfvars

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ postgres_backup_retention_days = 7
77
postgres_geo_redundant_backup_enabled = false
88
protect_keyvault = false
99
vnet_address_space = "10.142.0.0/16"
10-
deploy_database_as_container = true
10+
deploy_database_as_container = false
1111
seed_demo_data = true
12+
enable_alerting = false
1213
nhs_notify_api_message_batch_url = "https://int.api.service.nhs.uk/comms/v1/message-batches"

infrastructure/modules/container-apps/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ module "webapp" {
2222
container_app_environment_id = var.container_app_environment_id
2323
resource_group_name = azurerm_resource_group.main.name
2424
fetch_secrets_from_app_key_vault = var.fetch_secrets_from_app_key_vault
25-
infra_key_vault_name = "kv-${var.app_short_name}-${var.env_config}-inf"
26-
infra_key_vault_rg = "rg-${var.app_short_name}-${var.env_config}-infra"
25+
infra_key_vault_name = var.infra_key_vault_name
26+
infra_key_vault_rg = var.infra_key_vault_rg
2727
enable_auth = var.enable_auth
2828
app_key_vault_id = var.app_key_vault_id
2929
docker_image = var.docker_image

infrastructure/modules/container-apps/postgres.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ module "postgres" {
4646
}
4747

4848
# alerts
49-
action_group_id = var.action_group_id
50-
enable_monitoring = var.enable_monitoring
49+
action_group_id = var.action_group_id
50+
enable_monitoring = var.enable_alerting
5151

5252

5353
databases = {

infrastructure/modules/container-apps/variables.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ variable "use_apex_domain" {
144144
type = bool
145145
}
146146

147-
variable "enable_monitoring" {
147+
variable "enable_alerting" {
148148
description = "Whether monitoring and alerting is enabled for the PostgreSQL Flexible Server."
149149
type = bool
150150
}
@@ -165,6 +165,15 @@ variable "action_group_id" {
165165
description = "ID of the action group to notify."
166166
}
167167

168+
variable "infra_key_vault_name" {
169+
description = "Name of the infra key vault"
170+
type = string
171+
}
172+
173+
variable "infra_key_vault_rg" {
174+
description = "Name of the infra key vault resource group"
175+
type = string
176+
}
168177

169178
locals {
170179
resource_group_name = "rg-${var.app_short_name}-${var.environment}-container-app-uks"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
data "azurerm_key_vault" "infra" {
2+
provider = azurerm.hub
3+
4+
name = var.infra_key_vault_name
5+
resource_group_name = var.infra_key_vault_rg
6+
}
7+
8+
data "azurerm_key_vault_secret" "infra" {
9+
name = "monitoring-email-address"
10+
key_vault_id = data.azurerm_key_vault.infra.id
11+
}

infrastructure/modules/infra/monitor_action_group.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module "monitor_action_group" {
88
email_receiver = {
99
email = {
1010
name = "email"
11-
email_address = var.monitoring_email_address
11+
email_address = data.azurerm_key_vault_secret.infra.value
1212
}
1313
}
1414
}

infrastructure/modules/infra/variables.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ variable "protect_keyvault" {
3333
type = bool
3434
}
3535

36-
variable "monitoring_email_address" {
37-
description = "monitoring email address"
36+
variable "infra_key_vault_name" {
37+
description = "Name of the infra key vault"
38+
type = string
39+
}
40+
41+
variable "infra_key_vault_rg" {
42+
description = "Name of the infra key vault resource group"
3843
type = string
3944
}
4045

infrastructure/terraform/main.tf

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ module "infra" {
88
azurerm.hub = azurerm.hub
99
}
1010

11-
monitoring_email_address = var.monitoring_email_address
12-
region = local.region
13-
resource_group_name = local.resource_group_name
14-
app_short_name = var.app_short_name
15-
environment = var.env_config
16-
hub = var.hub
17-
protect_keyvault = var.protect_keyvault
18-
vnet_address_space = var.vnet_address_space
11+
region = local.region
12+
resource_group_name = local.resource_group_name
13+
infra_key_vault_name = local.infra_key_vault_name
14+
infra_key_vault_rg = local.infra_key_vault_rg
15+
app_short_name = var.app_short_name
16+
environment = var.env_config
17+
hub = var.hub
18+
protect_keyvault = var.protect_keyvault
19+
vnet_address_space = var.vnet_address_space
1920
}
2021

2122
module "shared_config" {
@@ -39,7 +40,7 @@ module "container-apps" {
3940
region = local.region
4041
action_group_id = var.deploy_infra ? module.infra[0].monitor_action_group_id : data.azurerm_monitor_action_group.main[0].id
4142
alert_window_size = var.alert_window_size
42-
enable_monitoring = var.enable_monitoring
43+
enable_alerting = var.enable_alerting
4344
app_key_vault_id = var.deploy_infra ? module.infra[0].app_key_vault_id : data.azurerm_key_vault.app_key_vault[0].id
4445
app_short_name = var.app_short_name
4546
allowed_paths = var.allowed_paths
@@ -65,4 +66,6 @@ module "container-apps" {
6566
main_subnet_id = var.deploy_infra ? module.infra[0].main_subnet_id : data.azurerm_subnet.main[0].id
6667
seed_demo_data = var.seed_demo_data
6768
use_apex_domain = var.use_apex_domain
69+
infra_key_vault_name = local.infra_key_vault_name
70+
infra_key_vault_rg = local.infra_key_vault_rg
6871
}

infrastructure/terraform/variables.tf

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,17 @@ variable "alert_window_size" {
141141
description = "The period of time that is used to monitor alert activity e.g. PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H. The interval between checks is adjusted accordingly."
142142
}
143143

144-
variable "enable_monitoring" {
144+
variable "enable_alerting" {
145145
description = "Whether monitoring and alerting is enabled for the PostgreSQL Flexible Server."
146146
type = bool
147147
default = false
148148
}
149149

150-
variable "monitoring_email_address" {
151-
description = "monitoring email address"
152-
type = string
153-
default = null
154-
}
155150

156151
locals {
157152
region = "uksouth"
158153

159-
resource_group_name = "rg-${var.app_short_name}-${var.env_config}-uks"
154+
resource_group_name = "rg-${var.app_short_name}-${var.env_config}-uks"
155+
infra_key_vault_name = "kv-${var.app_short_name}-${var.env_config}-inf"
156+
infra_key_vault_rg = "rg-${var.app_short_name}-${var.env_config}-infra"
160157
}

0 commit comments

Comments
 (0)