Skip to content

Commit aff6019

Browse files
authored
Merge pull request #457 from NHSDigital/feat/DTOSS-11103-Spike-Azure-monitor-infrastructure-metrics
[DTOSS-11103]: Spike Azure monitor infrastructure metrics
2 parents f37cef5 + 3be1e54 commit aff6019

File tree

11 files changed

+121
-14
lines changed

11 files changed

+121
-14
lines changed

infrastructure/environments/preprod/variables.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ vnet_address_space = "10.10.0.0/16"
1111
nhs_notify_api_message_batch_url = "https://int.api.service.nhs.uk/comms/v1/message-batches"
1212
seed_demo_data = false
1313
allowed_paths = ["/notifications/message-status/create"]
14+
enable_alerting = true

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ module "postgres" {
4545
private_service_connection_is_manual = false
4646
}
4747

48+
# alerts
49+
action_group_id = var.action_group_id
50+
enable_monitoring = var.enable_alerting
51+
4852
databases = {
4953
db1 = {
5054
collation = "en_US.utf8"

infrastructure/modules/container-apps/variables.tf

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,42 @@ variable "region" {
137137
variable "seed_demo_data" {
138138
description = "Whether or not to seed the demo data in the database."
139139
type = bool
140-
default = false
141140
}
142141

143142
variable "use_apex_domain" {
144143
description = "Use apex domain for the Front Door endpoint. Set to true for production."
145144
type = bool
146145
}
147146

147+
variable "enable_alerting" {
148+
description = "Whether monitoring and alerting is enabled for the PostgreSQL Flexible Server."
149+
type = bool
150+
}
151+
152+
variable "alert_window_size" {
153+
type = string
154+
nullable = false
155+
validation {
156+
condition = contains(["PT1M", "PT5M", "PT15M", "PT30M", "PT1H", "PT6H", "PT12H"], var.alert_window_size)
157+
error_message = "The alert_window_size must be one of: PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H"
158+
}
159+
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."
160+
}
161+
162+
variable "action_group_id" {
163+
type = string
164+
description = "ID of the action group to notify."
165+
}
166+
167+
variable "infra_key_vault_name" {
168+
description = "Name of the infra key vault"
169+
type = string
170+
}
171+
172+
variable "infra_key_vault_rg" {
173+
description = "Name of the infra key vault resource group"
174+
type = string
175+
}
148176

149177
locals {
150178
resource_group_name = "rg-${var.app_short_name}-${var.environment}-container-app-uks"
@@ -162,8 +190,8 @@ locals {
162190
common_env = merge(
163191
local.env_vars_from_yaml,
164192
{
165-
SSL_MODE = "require"
166-
DJANGO_ENV = var.env_config
193+
SSL_MODE = "require"
194+
DJANGO_ENV = var.env_config
167195
}
168196
)
169197

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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module "monitor_action_group" {
2+
source = "../dtos-devops-templates/infrastructure/modules/monitor-action-group"
3+
4+
name = "${module.shared_config.names.monitor-action-group}-${var.environment}"
5+
resource_group_name = azurerm_resource_group.main.name
6+
location = var.region
7+
short_name = "ag-${var.environment}"
8+
email_receiver = {
9+
email = {
10+
name = "email"
11+
email_address = data.azurerm_key_vault_secret.infra.value
12+
}
13+
}
14+
}

infrastructure/modules/infra/output.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ output "postgres_subnet_id" {
2525
output "main_subnet_id" {
2626
value = module.main_subnet.id
2727
}
28+
29+
output "monitor_action_group_id" {
30+
value = module.monitor_action_group.monitor_action_group.id
31+
}

infrastructure/modules/infra/variables.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ variable "vnet_address_space" {
3131
variable "protect_keyvault" {
3232
description = "Ability to recover the key vault or its secrets after deletion"
3333
type = bool
34-
default = true
34+
}
35+
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"
43+
type = string
3544
}
3645

3746
locals {

infrastructure/terraform/data.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ data "azurerm_subnet" "main" {
3535
virtual_network_name = module.shared_config.names.virtual-network-lowercase
3636
resource_group_name = local.resource_group_name
3737
}
38+
39+
data "azurerm_monitor_action_group" "main" {
40+
count = var.deploy_infra ? 0 : 1
41+
42+
name = "${module.shared_config.names.monitor-action-group}-${var.env_config}"
43+
resource_group_name = local.resource_group_name
44+
}

infrastructure/terraform/main.tf

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

11-
region = local.region
12-
resource_group_name = local.resource_group_name
13-
app_short_name = var.app_short_name
14-
environment = var.env_config
15-
hub = var.hub
16-
protect_keyvault = var.protect_keyvault
17-
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
1820
}
1921

2022
module "shared_config" {
@@ -36,6 +38,9 @@ module "container-apps" {
3638
}
3739

3840
region = local.region
41+
action_group_id = var.deploy_infra ? module.infra[0].monitor_action_group_id : data.azurerm_monitor_action_group.main[0].id
42+
alert_window_size = var.alert_window_size
43+
enable_alerting = var.enable_alerting
3944
app_key_vault_id = var.deploy_infra ? module.infra[0].app_key_vault_id : data.azurerm_key_vault.app_key_vault[0].id
4045
app_short_name = var.app_short_name
4146
allowed_paths = var.allowed_paths
@@ -61,4 +66,6 @@ module "container-apps" {
6166
main_subnet_id = var.deploy_infra ? module.infra[0].main_subnet_id : data.azurerm_subnet.main[0].id
6267
seed_demo_data = var.seed_demo_data
6368
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
6471
}

0 commit comments

Comments
 (0)