Skip to content

Commit 95ad294

Browse files
committed
Adds Container App health probes and configurable settings
Integrates liveness, readiness, and startup probes; externalizes replica counts, CPU, memory, container registry, and tags as variables; restructures identity and registry blocks; renames registry variable.
1 parent 86cd90b commit 95ad294

6 files changed

Lines changed: 104 additions & 45 deletions

File tree

Infra/modules/container_app/main.tf

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,41 @@ resource "azurerm_container_app" "app" {
1010
resource_group_name = var.resource_group_name
1111
revision_mode = "Single"
1212
workload_profile_name = "Consumption"
13+
tags = var.tags
14+
15+
identity {
16+
type = "UserAssigned"
17+
identity_ids = [var.identity_id]
18+
}
19+
20+
registry {
21+
server = var.container_registry_login_server
22+
identity = var.identity_id
23+
}
1324

1425
template {
15-
min_replicas = 0
16-
max_replicas = 1
26+
min_replicas = var.min_replicas
27+
max_replicas = var.max_replicas
1728

1829
container {
1930
name = var.name
20-
// NOTE: Initial container image will be replaced by azure pipelines deploy
21-
image = "${var.registry_server}/crccheck/hello-world:latest"
22-
cpu = "0.5"
23-
memory = "1Gi"
31+
image = "${var.container_registry_login_server}/crccheck/hello-world:latest"
32+
cpu = var.cpu
33+
memory = var.memory
2434

2535
env {
26-
# Port for crccheck/hello-world to listen on
2736
name = "PORT"
2837
value = "8080"
2938
}
3039

3140
env {
3241
name = "ASPNETCORE_HTTP_PORTS"
33-
value = "8080"
42+
value = "8080;8081"
43+
}
44+
45+
env {
46+
name = "HEALTH_PORT"
47+
value = "8081"
3448
}
3549

3650
dynamic "env" {
@@ -40,32 +54,46 @@ resource "azurerm_container_app" "app" {
4054
value = env.value
4155
}
4256
}
43-
}
44-
}
4557

46-
identity {
47-
type = "UserAssigned"
48-
identity_ids = [var.identity_id]
58+
liveness_probe {
59+
path = "/alive"
60+
port = 8081
61+
transport = "HTTP"
62+
initial_delay = 10
63+
interval_seconds = 30
64+
}
65+
66+
readiness_probe {
67+
path = "/alive"
68+
port = 8081
69+
transport = "HTTP"
70+
interval_seconds = 10
71+
}
72+
73+
startup_probe {
74+
path = "/health"
75+
port = 8081
76+
transport = "HTTP"
77+
interval_seconds = 5
78+
failure_count_threshold = 15 # 5 * 15 = 75 seconds
79+
}
80+
}
4981
}
5082

5183
ingress {
5284
external_enabled = true
5385
target_port = 8080
86+
transport = "auto"
5487

5588
traffic_weight {
5689
percentage = 100
5790
latest_revision = true
5891
}
5992
}
6093

61-
registry {
62-
server = var.registry_server
63-
identity = var.identity_id
64-
}
65-
6694
lifecycle {
6795
ignore_changes = [
68-
template[0].container[0].image
96+
template[0].container[0].image,
6997
]
7098
}
7199
}

Infra/modules/container_app/variables.tf

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,53 @@ variable "resource_group_name" {
77
description = "Name of the resource group"
88
type = string
99
}
10+
variable "identity_id" {
11+
description = "The resource ID of the user-assigned managed identity."
12+
type = string
13+
}
1014

1115
variable "container_app_environment_id" {
1216
description = "ID of the Container App Environment"
1317
type = string
1418
}
1519

16-
variable "env_vars" {
17-
description = "Environment variables for the container"
18-
type = map(string)
19-
default = {}
20+
variable "container_registry_login_server" {
21+
description = "Container registry server"
22+
type = string
2023
}
2124

22-
variable "identity_id" {
23-
description = "Resource ID of the User Assigned Identity"
24-
type = string
25+
variable "cpu" {
26+
description = "CPU cores allocated to the container (e.g. 0.5, 1.0)."
27+
type = number
28+
default = 0.5
2529
}
2630

27-
variable "registry_server" {
28-
description = "Container registry server"
31+
variable "memory" {
32+
description = "Memory allocated to the container (e.g. 1Gi)."
2933
type = string
34+
default = "1Gi"
35+
}
36+
37+
variable "min_replicas" {
38+
description = "Minimum number of replicas."
39+
type = number
40+
default = 0
41+
}
42+
43+
variable "max_replicas" {
44+
description = "Maximum number of replicas."
45+
type = number
46+
default = 1
47+
}
48+
49+
variable "env_vars" {
50+
description = "Map of environment variables for the container."
51+
type = map(string)
52+
default = {}
53+
}
54+
55+
variable "tags" {
56+
description = "Tags to apply to all resources"
57+
type = map(string)
58+
default = {}
3059
}

Infra/modules/container_app_environment/variables.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ variable "resource_group" {
66
})
77
}
88

9-
variable "tags" {
10-
description = "Tags to apply to all resources"
11-
type = map(string)
12-
default = {}
13-
}
14-
159
variable "container_app_environment_name" {
1610
description = "Environment variables for the container app"
1711
type = string
@@ -20,4 +14,10 @@ variable "container_app_environment_name" {
2014
variable "identity_id" {
2115
description = "ID of the managed identity"
2216
type = string
17+
}
18+
19+
variable "tags" {
20+
description = "Tags to apply to all resources"
21+
type = map(string)
22+
default = {}
2323
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
output "container_registry_id" {
2-
value = azurerm_container_registry.acr.id
2+
description = "The ID of the container registry."
3+
value = azurerm_container_registry.acr.id
34
}
45

56
output "login_server" {
6-
value = azurerm_container_registry.acr.login_server
7-
}
7+
description = "The login server URL of the container registry."
8+
value = azurerm_container_registry.acr.login_server
9+
}

Infra/modules/container_registry/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variable "resource_group" {
77
}
88

99
variable "name" {
10-
description = "Name of the container registry"
10+
description = "The name of the container registry. Must be globally unique, alphanumeric only."
1111
type = string
1212
}
1313

@@ -22,7 +22,7 @@ variable "push_identity_ids" {
2222
}
2323

2424
variable "sku" {
25-
description = "The SKU of the container registry"
25+
description = "The SKU of the container registry (Basic, Standard, Premium)."
2626
type = string
2727
default = "Basic"
2828
}
@@ -31,4 +31,4 @@ variable "tags" {
3131
description = "Tags to apply to all resources"
3232
type = map(string)
3333
default = {}
34-
}
34+
}

Infra/prod/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ module "container_app_environment" {
4444
module "backend_container_app" {
4545
source = "../modules/container_app"
4646

47-
name = "reactapp-${lower(local.environment)}-backend"
48-
container_app_environment_id = module.container_app_environment.container_app_environment_id
49-
resource_group_name = azurerm_resource_group.resource_group.name
50-
identity_id = azurerm_user_assigned_identity.app_identity.id
51-
registry_server = var.acr_login_server
47+
name = "reactapp-${lower(local.environment)}-backend"
48+
container_app_environment_id = module.container_app_environment.container_app_environment_id
49+
resource_group_name = azurerm_resource_group.resource_group.name
50+
identity_id = azurerm_user_assigned_identity.app_identity.id
51+
container_registry_login_server = var.acr_login_server
5252

5353
env_vars = {
5454
# Run EF Core migrations on startup for Azure deployments

0 commit comments

Comments
 (0)