Skip to content

Commit c9e38e2

Browse files
authored
Merge branch 'main' into PPHA-714-Script-to-get-submitted-eligible-participants
2 parents 4180721 + 81b1ee7 commit c9e38e2

15 files changed

Lines changed: 250 additions & 0 deletions

File tree

core

Whitespace-only changes.

docs/infrastructure/create-environment.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,16 @@ Add the infrastructure secrets to the _inf_ key vault `kv-lungcs-[environment]-i
133133

134134
- assign yourself "Key Vault Secrets User" to application key vault to run the terraform code from the CLI inside the AVD when first trying to deploy the application.
135135
- assign yourself "Data Blob Reader" to State file storage account to run the terraform code from the CLI inside the AVD when first trying to deploy the application.
136+
137+
## Connect to Postgres Database
138+
139+
- Add your user as a member to the respective Entra ID group:
140+
- `postgres_lungcs_[environment]_uks_admin`
141+
- Log into the correct ADV for your environment type (either nonlive or live)
142+
- Run the following commands on the CLI to log into the database: -
143+
- `export PGPASSWORD="$(az account get-access-token --resource https://ossrdbms-aad.database.windows.net --query accessToken --output tsv)"`
144+
- `psql "host=postgres-lungcs-[environment]-uks.postgres.database.azure.com \
145+
port=5432 \
146+
dbname=[database] \
147+
user=postgres_lungcs_[environment]_uks_admin \
148+
sslmode=require"`
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
resource "azurerm_monitor_scheduled_query_rules_alert_v2" "five_hundred_error_alert" {
2+
count = var.enable_alerting ? 1 : 0
3+
4+
auto_mitigation_enabled = false
5+
description = "An alert triggered by 500 errors logged in code"
6+
enabled = var.enable_alerting
7+
evaluation_frequency = "PT5M"
8+
location = var.region
9+
name = "${var.app_short_name}-500-error-alert"
10+
resource_group_name = azurerm_resource_group.main.name
11+
scopes = [var.action_group_id]
12+
severity = 2
13+
skip_query_validation = false
14+
window_duration = "PT5M"
15+
workspace_alerts_storage_enabled = false
16+
17+
action {
18+
action_groups = [var.action_group_id]
19+
}
20+
21+
criteria {
22+
operator = "GreaterThan"
23+
query = <<-QUERY
24+
ContainerAppConsoleLogs_CL
25+
| where Log contains "[ERROR]"
26+
QUERY
27+
threshold = 0
28+
time_aggregation_method = "Count"
29+
30+
failing_periods {
31+
minimum_failing_periods_to_trigger_alert = 1
32+
number_of_evaluation_periods = 1
33+
}
34+
}
35+
}

infrastructure/modules/container-apps/jobs.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
locals {
2+
scheduled_jobs = {
3+
collect_metrics = {
4+
cron_expression = "0 */6 * * *"
5+
environment_variables = {
6+
ENVIRONMENT = var.environment
7+
}
8+
job_short_name = "rs"
9+
job_container_args = "request_summary"
10+
}
11+
}
12+
}
13+
114
module "db_setup" {
215
source = "../dtos-devops-templates/infrastructure/modules/container-app-job"
316

@@ -25,3 +38,54 @@ module "db_setup" {
2538
]
2639

2740
}
41+
42+
module "scheduled_jobs" {
43+
source = "../dtos-devops-templates/infrastructure/modules/container-app-job"
44+
45+
for_each = local.scheduled_jobs
46+
47+
name = "${var.app_short_name}-${each.value.job_short_name}-${var.environment}"
48+
container_app_environment_id = var.container_app_environment_id
49+
resource_group_name = azurerm_resource_group.main.name
50+
51+
fetch_secrets_from_app_key_vault = var.fetch_secrets_from_app_key_vault
52+
app_key_vault_id = var.app_key_vault_id
53+
54+
container_command = ["/bin/sh", "-c"]
55+
container_args = [
56+
"python manage.py ${each.value.job_container_args}"
57+
]
58+
59+
docker_image = var.docker_image
60+
replica_retry_limit = 0
61+
user_assigned_identity_ids = flatten([
62+
[module.azure_blob_storage_identity.id],
63+
var.deploy_database_as_container ? [] : [module.db_connect_identity[0].id]
64+
])
65+
66+
environment_variables = merge(
67+
local.common_env,
68+
{
69+
"STORAGE_ACCOUNT_NAME" = module.storage.storage_account_name,
70+
"BLOB_MI_CLIENT_ID" = module.azure_blob_storage_identity.client_id,
71+
},
72+
each.value.environment_variables,
73+
var.deploy_database_as_container ? local.container_db_env : local.azure_db_env
74+
)
75+
secret_variables = merge(
76+
{ SLACK_WEBHOOK_URL = var.slack_webhook_url },
77+
var.deploy_database_as_container ? { DATABASE_PASSWORD = resource.random_password.admin_password[0].result } : {}
78+
)
79+
80+
# alerts
81+
action_group_id = var.action_group_id
82+
enable_alerting = var.enable_alerting
83+
log_analytics_workspace_id = var.log_analytics_workspace_audit_id
84+
85+
# Ensure RBAC role assignments are created before the job definition finalizes
86+
depends_on = [
87+
module.blob_storage_role_assignment,
88+
]
89+
90+
cron_expression = each.value.cron_expression
91+
}

infrastructure/modules/container-apps/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ variable "infra_key_vault_rg" {
196196
type = string
197197
}
198198

199+
variable "slack_webhook_url" {
200+
description = "slack_webhook_url is the URL used to send alerts to Slack. It should be stored as a secret in the infra key vault with the name 'slack-webhook-url'."
201+
type = string
202+
}
203+
199204
locals {
200205
resource_group_name = "rg-${var.app_short_name}-${var.environment}-container-app-uks"
201206

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module "logic_app_slack_alert" {
2+
count = var.enable_alerting ? 1 : 0
3+
4+
source = "../dtos-devops-templates/infrastructure/modules/logic-app-slack-alert"
5+
6+
name = "logic-${var.app_short_name}-${var.environment}-slack-alerts"
7+
resource_group_name = azurerm_resource_group.main.name
8+
location = var.region
9+
slack_webhook_url = var.slack_webhook_url
10+
}
11+
12+
resource "azurerm_monitor_action_group" "slack" {
13+
count = var.enable_alerting ? 1 : 0
14+
15+
name = "ag-slack-${var.app_short_name}-${var.environment}-uks"
16+
resource_group_name = azurerm_resource_group.main.name
17+
short_name = "slack"
18+
19+
webhook_receiver {
20+
name = "logic-app-slack"
21+
service_uri = module.logic_app_slack_alert[0].trigger_callback_url
22+
use_common_alert_schema = true
23+
}
24+
}

infrastructure/modules/infra/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ variable "enable_alerting" {
7373
type = bool
7474
}
7575

76+
variable "slack_webhook_url" {
77+
description = "slack_webhook_url is the URL used to send alerts to Slack. It should be stored as a secret in the infra key vault with the name 'slack-webhook-url'."
78+
type = string
79+
}
80+
7681
locals {
7782
hub_vnet_rg_name = "rg-hub-${var.hub}-uks-bootstrap"
7883
hub_vnet_name = "vnet-hub-${var.hub}-uks"

infrastructure/terraform/spoke/data.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,17 @@ data "azurerm_application_insights" "app_insights" {
4949
name = "appi-${var.env_config}-uks-${var.app_short_name}"
5050
resource_group_name = local.resource_group_name
5151
}
52+
53+
data "azurerm_key_vault" "infra" {
54+
provider = azurerm.hub
55+
56+
name = local.infra_key_vault_name
57+
resource_group_name = local.infra_key_vault_rg
58+
}
59+
60+
data "azurerm_key_vault_secret" "slack_webhook_url" {
61+
name = "slack-webhook-url"
62+
key_vault_id = data.azurerm_key_vault.infra.id
63+
}
64+
65+
# git-sha-a85180497c23d742b5f92262b3b43069e44a4110

infrastructure/terraform/spoke/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module "infra" {
2222
vnet_address_space = var.vnet_address_space
2323
cae_zone_redundancy_enabled = var.cae_zone_redundancy_enabled
2424
enable_alerting = var.enable_alerting
25+
slack_webhook_url = data.azurerm_key_vault_secret.slack_webhook_url.value
2526
}
2627

2728
module "container-apps" {
@@ -69,4 +70,5 @@ module "container-apps" {
6970
use_apex_domain = var.use_apex_domain
7071
container_memory = var.container_memory
7172
min_replicas = var.min_replicas
73+
slack_webhook_url = data.azurerm_key_vault_secret.slack_webhook_url.value
7274
}

lung_cancer_screening/questions/management/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)