Skip to content

Commit e89ad77

Browse files
committed
Fix container app port clashing
To run multiple container apps within the same container app environment, it was necessary to assign unique external TCP ports to each app in order to prevent port conflicts. This issue was first identified when attempting to run multiple container app PostgreSQL databases within the same environment.
1 parent 3de1cfd commit e89ad77

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

infrastructure/modules/container-apps/postgres.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,7 @@ module "database_container" {
9797
infra_key_vault_name = "kv-${var.app_short_name}-${var.env_config}-inf"
9898
infra_key_vault_rg = "rg-${var.app_short_name}-${var.env_config}-infra"
9999
is_tcp_app = true
100-
port = 5432
100+
# postgres has a port of 5432
101+
port = 5432
102+
exposed_port = local.database_port
101103
}

infrastructure/modules/container-apps/variables.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ locals {
136136

137137
database_user = "admin"
138138
database_name = "manage_breast_screening"
139+
# Here we expect the environment to be in format pr-XXX. For example PR 1234 would have environment pr-1234 and port 2234
140+
database_port = var.deploy_database_as_container ? tonumber(regex("\\d+", var.environment)) + 1000 : 5432
139141

140142
common_env = {
141143
SSL_MODE = "require"
@@ -147,6 +149,7 @@ locals {
147149
DATABASE_HOST = var.deploy_database_as_container ? module.database_container[0].container_app_fqdn : null
148150
DATABASE_NAME = local.database_name
149151
DATABASE_USER = local.database_user
152+
DATABASE_PORT = local.database_port
150153
}
151154

152155
azure_db_env = {

manage_breast_screening/config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def boolean_env(key, default=None):
147147
"USER": environ.get("DATABASE_USER", ""),
148148
"PASSWORD": environ.get("DATABASE_PASSWORD", ""),
149149
"HOST": environ.get("DATABASE_HOST", ""),
150-
"PORT": "5432",
150+
"PORT": environ.get("DATABASE_PORT", "5432"),
151151
"OPTIONS": {"sslmode": environ.get("DATABASE_SSLMODE", "prefer")},
152152
}
153153
}

0 commit comments

Comments
 (0)