@@ -71,6 +71,18 @@ resource "azurerm_storage_share" "minio_share" {
7171 quota = var. storage_share_size
7272}
7373
74+ resource "azurerm_storage_share" "postgres_share" {
75+ name = " postgresstorageshare"
76+ storage_account_id = azurerm_storage_account. minio_storage_account . id
77+ quota = 10
78+ }
79+
80+ resource "azurerm_storage_share" "keycloak_share" {
81+ name = " keycloakstorageshare"
82+ storage_account_id = azurerm_storage_account. minio_storage_account . id
83+ quota = 10
84+ }
85+
7486data "azurerm_client_config" "current" {}
7587
7688resource "azurerm_key_vault" "minio_kv" {
@@ -184,6 +196,21 @@ resource "azurerm_network_security_rule" "allow_https_api" {
184196 network_security_group_name = azurerm_network_security_group. agw_nsg . name
185197}
186198
199+ resource "azurerm_network_security_rule" "allow_https_keycloak" {
200+ count = length (local. allowed_ips_list )
201+ name = " AllowHTTPS-Keycloak-${ count . index } "
202+ priority = 250 + count. index
203+ direction = " Inbound"
204+ access = " Allow"
205+ protocol = " Tcp"
206+ source_port_range = " *"
207+ destination_port_range = " 8444"
208+ source_address_prefix = local. allowed_ips_list [count . index ]
209+ destination_address_prefix = " *"
210+ resource_group_name = azurerm_resource_group. minio_rg . name
211+ network_security_group_name = azurerm_network_security_group. agw_nsg . name
212+ }
213+
187214resource "azurerm_network_security_rule" "allow_agw_management" {
188215 name = " AllowApplicationGatewayManagement"
189216 priority = 300
@@ -262,6 +289,11 @@ resource "azurerm_application_gateway" "minio_agw" {
262289 port = 8443
263290 }
264291
292+ frontend_port {
293+ name = " https-keycloak"
294+ port = 8444
295+ }
296+
265297 ssl_certificate {
266298 name = " minio-cert"
267299 key_vault_secret_id = azurerm_key_vault_certificate. minio_cert . secret_id
@@ -296,6 +328,18 @@ resource "azurerm_application_gateway" "minio_agw" {
296328 pick_host_name_from_backend_http_settings = false
297329 }
298330
331+ probe {
332+ name = " keycloak-health-probe"
333+ protocol = " Http"
334+ path = " /health/ready"
335+ host = azurerm_container_group. minio_aci_container_group . ip_address
336+ interval = 30
337+ timeout = 20
338+ unhealthy_threshold = 3
339+ port = 8082
340+ pick_host_name_from_backend_http_settings = false
341+ }
342+
299343 backend_http_settings {
300344 name = " ui-http"
301345 port = 8080
@@ -327,6 +371,21 @@ resource "azurerm_application_gateway" "minio_agw" {
327371
328372 }
329373
374+ backend_http_settings {
375+ name = " keycloak-http"
376+ port = 8082
377+ protocol = " Http"
378+ request_timeout = 300
379+ pick_host_name_from_backend_address = false
380+ cookie_based_affinity = " Disabled"
381+ probe_name = " keycloak-health-probe"
382+ connection_draining {
383+ enabled = true
384+ drain_timeout_sec = 300
385+ }
386+
387+ }
388+
330389 http_listener {
331390 name = " listener-ui"
332391 frontend_ip_configuration_name = " public-ip"
@@ -343,6 +402,14 @@ resource "azurerm_application_gateway" "minio_agw" {
343402 ssl_certificate_name = " minio-cert"
344403 }
345404
405+ http_listener {
406+ name = " listener-keycloak"
407+ frontend_ip_configuration_name = " public-ip"
408+ frontend_port_name = " https-keycloak"
409+ protocol = " Https"
410+ ssl_certificate_name = " minio-cert"
411+ }
412+
346413 request_routing_rule {
347414 name = " rule-ui"
348415 rule_type = " Basic"
@@ -361,6 +428,15 @@ resource "azurerm_application_gateway" "minio_agw" {
361428 priority = 20
362429 }
363430
431+ request_routing_rule {
432+ name = " rule-keycloak"
433+ rule_type = " Basic"
434+ http_listener_name = " listener-keycloak"
435+ backend_address_pool_name = " coraza-backend-pool"
436+ backend_http_settings_name = " keycloak-http"
437+ priority = 30
438+ }
439+
364440 identity {
365441 type = " UserAssigned"
366442 identity_ids = [azurerm_user_assigned_identity . agw_identity . id ]
@@ -388,6 +464,116 @@ resource "azurerm_container_group" "minio_aci_container_group" {
388464 }
389465 }
390466
467+ container {
468+ name = " postgres"
469+ image = " postgres:16-alpine"
470+ cpu = " 0.5"
471+ memory = " 1.0"
472+ cpu_limit = 1.0
473+ memory_limit = 1.5
474+
475+ environment_variables = {
476+ POSTGRES_DB = var.postgres_db
477+ POSTGRES_USER = var.postgres_user
478+ POSTGRES_PASSWORD = var.postgres_password
479+ }
480+
481+ ports {
482+ port = 5432
483+ protocol = " TCP"
484+ }
485+
486+ volume {
487+ name = " postgres-data"
488+ mount_path = " /var/lib/postgresql/data"
489+ read_only = false
490+ storage_account_name = azurerm_storage_account. minio_storage_account . name
491+ storage_account_key = azurerm_storage_account. minio_storage_account . primary_access_key
492+ share_name = azurerm_storage_share. postgres_share . name
493+ }
494+
495+ liveness_probe {
496+ exec = [" pg_isready" , " -U" , var . postgres_user , " -d" , var . postgres_db ]
497+
498+ initial_delay_seconds = 30
499+ period_seconds = 10
500+ timeout_seconds = 5
501+ failure_threshold = 3
502+ }
503+ }
504+
505+ container {
506+ name = " keycloak"
507+ image = " quay.io/keycloak/keycloak:latest"
508+ cpu = " 1.0"
509+ memory = " 2.0"
510+ cpu_limit = 1.0
511+ memory_limit = 2.5
512+
513+ environment_variables = {
514+ KC_BOOTSTRAP_ADMIN_USERNAME = var.keycloak_admin_user
515+ KC_BOOTSTRAP_ADMIN_PASSWORD = var.keycloak_admin_password
516+ KC_HTTP_ENABLED = " true"
517+ KC_HOSTNAME_STRICT = " false"
518+ KC_PROXY_HEADERS = " xforwarded"
519+ KEYCLOAK_IMPORT = " /opt/keycloak/data/import/realm-config.json"
520+ KC_DB = " postgres"
521+ KC_DB_URL = " jdbc:postgresql://localhost/${ var . postgres_db } "
522+ KC_DB_USERNAME = var.postgres_user
523+ KC_DB_PASSWORD = var.postgres_password
524+ }
525+
526+ ports {
527+ port = 8080
528+ protocol = " TCP"
529+ }
530+
531+ volume {
532+ name = " keycloak-realm-config"
533+ mount_path = " /opt/keycloak/data/import"
534+ read_only = true
535+
536+ secret = {
537+ " minio-realm-config.json" = filebase64 (" ${ path . module } /keycloak-minio-docker/minio-realm-config.json" )
538+ }
539+ }
540+
541+ volume {
542+ name = " keycloak-data"
543+ mount_path = " /opt/keycloak/data/h2"
544+ read_only = false
545+ storage_account_name = azurerm_storage_account. minio_storage_account . name
546+ storage_account_key = azurerm_storage_account. minio_storage_account . primary_access_key
547+ share_name = azurerm_storage_share. keycloak_share . name
548+ }
549+
550+ commands = [" start" , " --import-realm" ]
551+
552+ liveness_probe {
553+ http_get {
554+ path = " /health/live"
555+ port = 8080
556+ scheme = " http"
557+ }
558+ initial_delay_seconds = 120
559+ period_seconds = 30
560+ timeout_seconds = 10
561+ failure_threshold = 3
562+ }
563+
564+ readiness_probe {
565+ http_get {
566+ path = " /health/ready"
567+ port = 8080
568+ scheme = " http"
569+ }
570+ initial_delay_seconds = 60
571+ period_seconds = 10
572+ timeout_seconds = 5
573+ failure_threshold = 3
574+ }
575+ }
576+
391577 container {
392578 name = " minio"
393579 image = var. minio_image
@@ -404,9 +590,16 @@ resource "azurerm_container_group" "minio_aci_container_group" {
404590 protocol = " TCP"
405591 }
406592 environment_variables = {
407- MINIO_ROOT_USER = var.minio_root_user
408- MINIO_ROOT_PASSWORD = var.minio_root_password
409- MINIO_BROWSER_REDIRECT_URL = " https://${ azurerm_public_ip . agw_pip . fqdn } "
593+ MINIO_ROOT_USER = var.minio_root_user
594+ MINIO_ROOT_PASSWORD = var.minio_root_password
595+ MINIO_BROWSER_REDIRECT_URL = " https://${ azurerm_public_ip . agw_pip . fqdn } "
596+ MINIO_IDENTITY_OPENID_CONFIG_URL = " http://localhost:8082/realms/minio_realm/.well-known/openid-configuration"
597+ MINIO_IDENTITY_OPENID_CLIENT_ID = " minio-client"
598+ MINIO_IDENTITY_OPENID_CLIENT_SECRET = var.keycloak_client_secret
599+ MINIO_IDENTITY_OPENID_CLAIM_NAME = " policy"
600+ MINIO_IDENTITY_OPENID_SCOPES = " openid,profile,email"
601+ MINIO_IDENTITY_OPENID_REDIRECT_URI = " https://${ azurerm_public_ip . agw_pip . fqdn } /oauth_callback"
602+ MINIO_IDENTITY_OPENID_DISPLAY_NAME = " Login with SSO"
410603 }
411604
412605 volume {
0 commit comments