File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -435,7 +435,33 @@ resource "null_resource" "configure_github_auth" {
435435}
436436
437437# ==============================================================================
438- # 10. ACR Task for CI/CD (Optional)
438+ # 10. Sticky Sessions for MCP Session Affinity
439+ # ==============================================================================
440+ # MCP sessions are stored in-memory. When running multiple replicas, requests
441+ # must be routed to the same replica to maintain session state. Sticky sessions
442+ # use HTTP cookies (ARRAffinity) to ensure session affinity.
443+ resource "null_resource" "sticky_sessions" {
444+ count = var. enable_sticky_sessions ? 1 : 0
445+
446+ triggers = {
447+ container_app_id = azurerm_container_app.app.id
448+ sticky_sessions = var.enable_sticky_sessions
449+ }
450+
451+ provisioner "local-exec" {
452+ command = <<- EOT
453+ az containerapp ingress sticky-sessions set \
454+ --name ${ local . container_app_name } \
455+ --resource-group ${ var . resource_group_name } \
456+ --affinity sticky
457+ EOT
458+ }
459+
460+ depends_on = [azurerm_container_app . app ]
461+ }
462+
463+ # ==============================================================================
464+ # 11. ACR Task for CI/CD (Optional)
439465# ==============================================================================
440466resource "azurerm_container_registry_task" "build" {
441467 count = var. github_repo_url != " " && var. github_pat != " " ? 1 : 0
Original file line number Diff line number Diff line change @@ -127,3 +127,17 @@ output "github_callback_url" {
127127 description = " GitHub OAuth callback URL"
128128 value = " https://${ azurerm_container_app . app . ingress [0 ]. fqdn } /.auth/login/github/callback"
129129}
130+
131+ # ------------------------------------------------------------------------------
132+ # Session Affinity
133+ # ------------------------------------------------------------------------------
134+
135+ output "sticky_sessions_enabled" {
136+ description = " Whether sticky sessions are enabled for MCP session affinity"
137+ value = var. enable_sticky_sessions
138+ }
139+
140+ output "sticky_sessions_verify_command" {
141+ description = " Command to verify sticky sessions configuration"
142+ value = " az containerapp show --name ${ azurerm_container_app . app . name } --resource-group ${ var . resource_group_name } --query \" properties.configuration.ingress.stickySessions\" "
143+ }
Original file line number Diff line number Diff line change @@ -164,3 +164,13 @@ variable "github_pat" {
164164 default = " "
165165 sensitive = true
166166}
167+
168+ # ------------------------------------------------------------------------------
169+ # Session Affinity Variables
170+ # ------------------------------------------------------------------------------
171+
172+ variable "enable_sticky_sessions" {
173+ description = " Enable sticky sessions for MCP session affinity. Required for multi-replica deployments with stateful MCP sessions."
174+ type = bool
175+ default = true
176+ }
You can’t perform that action at this time.
0 commit comments