Skip to content

Commit 11d7773

Browse files
authored
feat: DTOSS-10749 setup wiremock server (#1620)
feat: wiremock container app, cont app environemnt, compose file, dockerfile
1 parent ed7afc2 commit 11d7773

File tree

11 files changed

+138
-10
lines changed

11 files changed

+138
-10
lines changed

application/CohortManager/compose.deps.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ services:
7272
- SYS_PTRACE
7373
restart: "no"
7474

75-
wiremock:
76-
container_name: wiremock
77-
networks: [cohman-network]
78-
image: wiremock/wiremock
79-
ports:
80-
- "8080:8080"
81-
volumes:
82-
- ./Set-up/wiremock/mappings:/home/wiremock/mappings
83-
command: --verbose --root-dir /home/wiremock
84-
8575
networks:
8676
cohman-network:
8777
name: cohman-network
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: cohort-manager-pipeline
2+
services:
3+
4+
wiremock:
5+
container_name: wiremock
6+
networks: [cohman-network]
7+
build:
8+
context: ./src/Functions/
9+
dockerfile: Shared/Wiremock/Dockerfile
10+
ports:
11+
- "8080:8080"
12+
volumes:
13+
- ./src/Functions/Shared/Wiremock/mappings:/home/wiremock/mappings
14+
command: --verbose --root-dir /home/wiremock
15+
16+
networks:
17+
cohman-network:
18+
external: true

application/CohortManager/compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ include:
55
- compose.core.yaml
66
- compose.cohort-distribution.yaml
77
- compose.pipeline.yaml
8+
- compose.wiremock.yaml
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Use the official WireMock image as the base
2+
FROM wiremock/wiremock:latest
3+
4+
# Copy the JSON mapping files into the container
5+
# WireMock automatically loads mappings from the /home/wiremock/mappings directory
6+
COPY /Shared/Wiremock/mappings /home/wiremock/mappings
7+
8+
# Use a default, non-root built in Wiremock user
9+
USER wiremock

application/CohortManager/Set-up/wiremock/mappings/servicenow_authentication.json renamed to application/CohortManager/src/Functions/Shared/Wiremock/mappings/servicenow_authentication.json

File renamed without changes.

application/CohortManager/Set-up/wiremock/mappings/servicenow_resolution.json renamed to application/CohortManager/src/Functions/Shared/Wiremock/mappings/servicenow_resolution.json

File renamed without changes.

application/CohortManager/Set-up/wiremock/mappings/servicenow_update.json renamed to application/CohortManager/src/Functions/Shared/Wiremock/mappings/servicenow_update.json

File renamed without changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
module "container-app" {
3+
for_each = local.container_apps_map
4+
5+
source = "../../../dtos-devops-templates/infrastructure/modules/container-app"
6+
7+
providers = {
8+
azurerm = azurerm
9+
azurerm.hub = azurerm.hub
10+
}
11+
12+
name = "ca-${lower(each.key)}"
13+
resource_group_name = azurerm_resource_group.core[each.value.region].name
14+
location = each.value.region
15+
16+
container_app_environment_id = module.container-app-environment["${each.value.container_app_environment_key}-${each.value.region}"].id
17+
user_assigned_identity_ids = each.value.add_user_assigned_identity ? [module.user_assigned_managed_identity_sql["${each.key}"].id] : []
18+
19+
acr_login_server = data.azurerm_container_registry.acr.login_server
20+
acr_managed_identity_id = each.value.container_registry_use_mi ? data.azurerm_user_assigned_identity.acr_mi.id : null
21+
docker_image = "${data.azurerm_container_registry.acr.login_server}/${each.value.docker_image}:${each.value.docker_env_tag != "" ? each.value.docker_env_tag : var.docker_image_tag}"
22+
23+
environment_variables = each.value.env_vars != null ? each.value.env_vars : {}
24+
25+
is_tcp_app = each.value.is_tcp_app
26+
is_web_app = each.value.is_web_app
27+
port = each.value.port
28+
29+
infra_key_vault_rg = each.value.infra_key_vault_rg
30+
infra_key_vault_name = each.value.infra_key_vault_name
31+
32+
depends_on = [
33+
module.azure_sql_server
34+
]
35+
}
36+
37+
locals {
38+
# There are multiple App Service Plans and possibly multiple regions.
39+
# We cannot nest for loops inside a map, so first iterate all permutations of both as a list of objects...
40+
container_apps_object_list = flatten([
41+
for region in keys(var.regions) : [
42+
for container_app, config in var.container_apps.apps : merge(
43+
{
44+
region = region # 1st iterator
45+
container_app = container_app # 2nd iterator
46+
},
47+
config, # the rest of the key/value pairs for a specific container_app
48+
{
49+
env_vars = merge(
50+
# Add environment variables defined specifically for this container app :
51+
config.env_vars_static,
52+
53+
# Add in the database connection string if the name of the variable is provided:
54+
config.add_user_assigned_identity != null && length(config.db_connection_string_name) > 0 ? {
55+
(config.db_connection_string_name) = "Server=tcp:${module.regions_config[region].names.sql-server}.database.windows.net,1433;Initial Catalog=${var.sqlserver.dbs.cohman.db_name_suffix};Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication='Active Directory Managed Identity';User ID=${module.user_assigned_managed_identity_sql["${container_app}-${region}"].client_id};"
56+
} : {},
57+
58+
# Add in the MANAGED_IDENTITY_CLIENT_ID environment variable if using a user assigned managed identity:
59+
config.add_user_assigned_identity != false ? {
60+
"MANAGED_IDENTITY_CLIENT_ID" = "${module.user_assigned_managed_identity_sql["${container_app}-${region}"].client_id}",
61+
"TARGET_SUBSCRIPTION_ID" = var.TARGET_SUBSCRIPTION_ID
62+
} : {}
63+
)
64+
}
65+
)
66+
]
67+
])
68+
69+
# ...then project the list of objects into a map with unique keys (combining the iterators), for consumption by a for_each meta argument
70+
container_apps_map = {
71+
for object in local.container_apps_object_list : "${object.container_app}-${object.region}" => object
72+
}
73+
}

infrastructure/tf-core/environments/development.tfvars

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ regions = {
5656
service_delegation_name = "Microsoft.App/environments"
5757
service_delegation_actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"]
5858
}
59+
container-app-default = {
60+
cidr_newbits = 7
61+
cidr_offset = 7
62+
delegation_name = "Microsoft.App/environments"
63+
service_delegation_name = "Microsoft.App/environments"
64+
service_delegation_actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"]
65+
}
5966
}
6067
}
6168
}
@@ -237,6 +244,9 @@ container_app_environments = {
237244
db-management = {
238245
zone_redundancy_enabled = false
239246
}
247+
default = {
248+
zone_redundancy_enabled = false
249+
}
240250
}
241251
}
242252

@@ -253,6 +263,22 @@ container_app_jobs = {
253263
}
254264
}
255265

266+
container_apps = {
267+
apps = {
268+
wiremock = {
269+
container_app_environment_key = "default"
270+
docker_image = "cohort-manager-wiremock"
271+
container_registry_use_mi = true
272+
add_user_assigned_identity = false
273+
is_tcp_app = false
274+
is_web_app = true
275+
port = 8080
276+
infra_key_vault_rg = null
277+
infra_key_vault_name = null
278+
}
279+
}
280+
}
281+
256282
diagnostic_settings = {
257283
metric_enabled = true
258284
}

infrastructure/tf-core/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,14 @@ variable "container_apps" {
189189
docker_env_tag = optional(string, "")
190190
docker_image = optional(string)
191191
is_web_app = optional(bool, false)
192+
is_tcp_app = optional(bool, false)
192193
container_registry_use_mi = optional(bool, false)
194+
db_connection_string_name = optional(string, "")
195+
add_user_assigned_identity = optional(bool, false)
196+
port = optional(number, 8080)
197+
infra_key_vault_name = optional(string, "")
198+
infra_key_vault_rg = optional(string, "")
199+
env_vars_static = optional(map(string), {})
193200
})), {})
194201
})
195202
}

0 commit comments

Comments
 (0)