From 2ba70b1381275fdb54a0d48b3f0dbafa9a1d3689 Mon Sep 17 00:00:00 2001 From: mamari90 <130982006+mamari90@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:35:28 +0100 Subject: [PATCH 1/5] prepared clone app service --- .../01_app_service_pdf_engine_clone.tf | 472 ++++++++++++++++++ 1 file changed, 472 insertions(+) create mode 100644 src/domains/printit-app/01_app_service_pdf_engine_clone.tf diff --git a/src/domains/printit-app/01_app_service_pdf_engine_clone.tf b/src/domains/printit-app/01_app_service_pdf_engine_clone.tf new file mode 100644 index 000000000..b8e06379a --- /dev/null +++ b/src/domains/printit-app/01_app_service_pdf_engine_clone.tf @@ -0,0 +1,472 @@ +################ +# node +################ + +module "printit_pdf_engine_app_service_clone" { + source = "./.terraform/modules/__v3__/app_service" + + count = var.is_feature_enabled.pdf_engine ? 1 : 0 + + vnet_integration = false + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + location = var.location + + # App service plan vars + plan_name = "${local.project}-plan-pdf-engine-clone" + sku_name = var.app_service_pdf_engine_sku_name + + # App service plan + name = "${local.project}-app-pdf-engine-clone" + client_cert_enabled = false + always_on = var.app_service_pdf_engine_always_on + + docker_image = "${data.azurerm_container_registry.container_registry.login_server}/pagopapdfengine" + docker_image_tag = "latest" + + health_check_path = "/info" + + ip_restriction_default_action = var.app_service_ip_restriction_default_action + + + app_settings = local.printit_pdf_engine_app_settings + + zone_balancing_enabled = false + allowed_subnets = [data.azurerm_subnet.apim_vnet.id] + allowed_ips = [] + + subnet_id = data.azurerm_subnet.printit_pdf_engine_app_service_snet[0].id + + tags = var.tags + +} + +module "printit_pdf_engine_slot_staging_clone" { + count = var.env_short != "d" && var.is_feature_enabled.pdf_engine ? 1 : 0 + + source = "./.terraform/modules/__v3__/app_service_slot" + + # App service plan + # app_service_plan_id = module.printit_pdf_engine_app_service.plan_id + app_service_id = module.printit_pdf_engine_app_service_clone[0].id + app_service_name = module.printit_pdf_engine_app_service_clone[0].name + + # App service + name = "staging" + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + location = var.location + + always_on = true + docker_image = "${data.azurerm_container_registry.container_registry.login_server}/pagopapdfengine" + docker_image_tag = "latest" + health_check_path = "/info" + + + # App settings + app_settings = local.printit_pdf_engine_app_settings + + allowed_subnets = [data.azurerm_subnet.apim_vnet.id] + allowed_ips = [] + subnet_id = data.azurerm_subnet.printit_pdf_engine_app_service_snet[0].id + + tags = var.tags + + +} + +resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_engine_autoscale_clone" { + count = var.env_short != "d" && var.is_feature_enabled.pdf_engine ? 1 : 0 + enabled = var.app_service_pdf_engine_autoscale_enabled + + name = "${local.project}-autoscale-pdf-engine-clone" + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + location = azurerm_resource_group.printit_pdf_engine_app_service_rg.location + target_resource_id = module.printit_pdf_engine_app_service_clone[0].plan_id + + profile { + name = "default" + + capacity { + default = 3 + minimum = var.env_short == "p" ? 3 : 1 + maximum = 10 + } + + # Requests + rule { + metric_trigger { + metric_name = "Requests" + metric_resource_id = module.printit_pdf_engine_app_service[0].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "GreaterThan" + threshold = 2000 + divide_by_instance_count = false + } + + scale_action { + direction = "Increase" + type = "ChangeCount" + value = "2" + cooldown = "PT5M" + } + } + + rule { + metric_trigger { + metric_name = "Requests" + metric_resource_id = module.printit_pdf_engine_app_service[0].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "LessThan" + threshold = 1000 + divide_by_instance_count = false + } + + scale_action { + direction = "Decrease" + type = "ChangeCount" + value = "1" + cooldown = "PT20M" + } + } + + # HttpResponseTime + + # Supported metrics for Microsoft.Web/sites + # 👀 https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-web-sites-metrics + rule { + metric_trigger { + metric_name = "HttpResponseTime" + metric_resource_id = module.printit_pdf_engine_app_service[0].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "GreaterThan" + threshold = 5 #sec + divide_by_instance_count = false + } + + scale_action { + direction = "Increase" + type = "ChangeCount" + value = "2" + cooldown = "PT5M" + } + } + + rule { + metric_trigger { + metric_name = "HttpResponseTime" + metric_resource_id = module.printit_pdf_engine_app_service[0].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "LessThan" + threshold = 2 #sec + divide_by_instance_count = false + } + + scale_action { + direction = "Decrease" + type = "ChangeCount" + value = "1" + cooldown = "PT20M" + } + } + + # CpuPercentage + + # Supported metrics for Microsoft.Web/sites + # 👀 https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-web-sites-metrics + rule { + metric_trigger { + metric_name = "CpuPercentage" + metric_resource_id = module.printit_pdf_engine_app_service[0].plan_id + metric_namespace = "microsoft.web/serverfarms" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "GreaterThan" + threshold = 75 + divide_by_instance_count = false + } + + scale_action { + direction = "Increase" + type = "ChangeCount" + value = "2" + cooldown = "PT5M" + } + } + + rule { + metric_trigger { + metric_name = "CpuPercentage" + metric_resource_id = module.printit_pdf_engine_app_service[0].plan_id + metric_namespace = "microsoft.web/serverfarms" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "LessThan" + threshold = 30 #sec + divide_by_instance_count = false + } + + scale_action { + direction = "Decrease" + type = "ChangeCount" + value = "1" + cooldown = "PT20M" + } + } + + + } +} + + +############### +#java +############### +module "printit_pdf_engine_app_service_java_clone" { + source = "./.terraform/modules/__v3__/app_service" + count = var.is_feature_enabled.pdf_engine ? 1 : 0 + + vnet_integration = false + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + location = var.location + + # App service plan vars + plan_name = "${local.project}-plan-pdf-engine-java-clone" + sku_name = var.app_service_pdf_engine_sku_name_java + zone_balancing_enabled = false + + # App service plan + name = "${local.project}-app-pdf-engine-java-clone" + client_cert_enabled = false + always_on = var.app_service_pdf_engine_always_on + docker_image = "${data.azurerm_container_registry.container_registry.login_server}/pagopapdfenginejava" + docker_image_tag = "latest" + + health_check_path = "/info" + + app_settings = local.printit_pdf_engine_app_settings_java + + ip_restriction_default_action = var.app_service_ip_restriction_default_action + allowed_subnets = [data.azurerm_subnet.apim_vnet.id] + allowed_ips = [] + + subnet_id = data.azurerm_subnet.printit_pdf_engine_app_service_snet[0].id + + tags = var.tags + + +} + +module "printit_pdf_engine_java_slot_staging_clone" { + count = var.env_short != "d" && var.is_feature_enabled.pdf_engine ? 1 : 0 + + source = "./.terraform/modules/__v3__/app_service_slot" + + # App service plan + # app_service_plan_id = module.printit_pdf_engine_app_service.plan_id + app_service_id = module.printit_pdf_engine_app_service_java_clone[0].id + app_service_name = module.printit_pdf_engine_app_service_java_clone[0].name + + # App service + name = "staging" + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + location = var.location + + always_on = true + docker_image = "${data.azurerm_container_registry.container_registry.login_server}/pagopapdfenginejava" + docker_image_tag = "latest" + health_check_path = "/info" + + + # App settings + app_settings = local.printit_pdf_engine_app_settings_java + + allowed_subnets = [data.azurerm_subnet.apim_vnet.id] + allowed_ips = [] + subnet_id = data.azurerm_subnet.printit_pdf_engine_app_service_snet[0].id + + tags = var.tags + + +} + +resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_engine_java_autoscale_clone" { + count = var.env_short != "d" && var.is_feature_enabled.pdf_engine ? 1 : 0 + + + name = "${local.project}-autoscale-pdf-engine-java-clone" + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + location = azurerm_resource_group.printit_pdf_engine_app_service_rg.location + target_resource_id = module.printit_pdf_engine_app_service_java_clone[0].plan_id + enabled = var.app_service_pdf_engine_autoscale_enabled + + profile { + name = "default" + + capacity { + default = 3 + minimum = var.env_short == "p" ? 3 : 1 + maximum = 10 + } + + # Requests + rule { + metric_trigger { + metric_name = "Requests" + metric_resource_id = module.printit_pdf_engine_app_service_java[0].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "GreaterThan" + threshold = 2000 + divide_by_instance_count = false + } + + scale_action { + direction = "Increase" + type = "ChangeCount" + value = "2" + cooldown = "PT5M" + } + } + + rule { + metric_trigger { + metric_name = "Requests" + metric_resource_id = module.printit_pdf_engine_app_service_java[0].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "LessThan" + threshold = 1000 + divide_by_instance_count = false + } + + scale_action { + direction = "Decrease" + type = "ChangeCount" + value = "1" + cooldown = "PT20M" + } + } + + # HttpResponseTime + + # Supported metrics for Microsoft.Web/sites + # 👀 https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-web-sites-metrics + rule { + metric_trigger { + metric_name = "HttpResponseTime" + metric_resource_id = module.printit_pdf_engine_app_service_java[0].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "GreaterThan" + threshold = 5 #sec + divide_by_instance_count = false + } + + scale_action { + direction = "Increase" + type = "ChangeCount" + value = "2" + cooldown = "PT5M" + } + } + + rule { + metric_trigger { + metric_name = "HttpResponseTime" + metric_resource_id = module.printit_pdf_engine_app_service_java[0].id + metric_namespace = "microsoft.web/sites" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "LessThan" + threshold = 2 #sec + divide_by_instance_count = false + } + + scale_action { + direction = "Decrease" + type = "ChangeCount" + value = "1" + cooldown = "PT20M" + } + } + + # CpuPercentage + + # Supported metrics for Microsoft.Web/sites + # 👀 https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-web-sites-metrics + rule { + metric_trigger { + metric_name = "CpuPercentage" + metric_resource_id = module.printit_pdf_engine_app_service_java[0].plan_id + metric_namespace = "microsoft.web/serverfarms" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "GreaterThan" + threshold = 75 + divide_by_instance_count = false + } + + scale_action { + direction = "Increase" + type = "ChangeCount" + value = "2" + cooldown = "PT5M" + } + } + + rule { + metric_trigger { + metric_name = "CpuPercentage" + metric_resource_id = module.printit_pdf_engine_app_service_java[0].plan_id + metric_namespace = "microsoft.web/serverfarms" + time_grain = "PT1M" + statistic = "Average" + time_window = "PT5M" + time_aggregation = "Average" + operator = "LessThan" + threshold = 30 #sec + divide_by_instance_count = false + } + + scale_action { + direction = "Decrease" + type = "ChangeCount" + value = "1" + cooldown = "PT20M" + } + } + } +} + From e4846f196b6782831d50ab357fbcca2f23ec698e Mon Sep 17 00:00:00 2001 From: mamari90 <130982006+mamari90@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:59:44 +0100 Subject: [PATCH 2/5] added printit configurations --- .../printit-app/01_app_service_pdf_engine_clone.tf | 12 ++++++------ src/domains/printit-app/04_apim_pdf_engine.tf | 4 ++-- src/domains/printit-app/99_variables.tf | 5 +++++ .../printit-app/env/itn-prod/terraform.tfvars | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/domains/printit-app/01_app_service_pdf_engine_clone.tf b/src/domains/printit-app/01_app_service_pdf_engine_clone.tf index b8e06379a..e6733c497 100644 --- a/src/domains/printit-app/01_app_service_pdf_engine_clone.tf +++ b/src/domains/printit-app/01_app_service_pdf_engine_clone.tf @@ -5,7 +5,7 @@ module "printit_pdf_engine_app_service_clone" { source = "./.terraform/modules/__v3__/app_service" - count = var.is_feature_enabled.pdf_engine ? 1 : 0 + count = var.is_feature_enabled.pdf_engine_clone ? 1 : 0 vnet_integration = false resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name @@ -41,7 +41,7 @@ module "printit_pdf_engine_app_service_clone" { } module "printit_pdf_engine_slot_staging_clone" { - count = var.env_short != "d" && var.is_feature_enabled.pdf_engine ? 1 : 0 + count = var.env_short != "d" && var.is_feature_enabled.pdf_engine_clone ? 1 : 0 source = "./.terraform/modules/__v3__/app_service_slot" @@ -74,7 +74,7 @@ module "printit_pdf_engine_slot_staging_clone" { } resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_engine_autoscale_clone" { - count = var.env_short != "d" && var.is_feature_enabled.pdf_engine ? 1 : 0 + count = var.env_short != "d" && var.is_feature_enabled.pdf_engine_clone ? 1 : 0 enabled = var.app_service_pdf_engine_autoscale_enabled name = "${local.project}-autoscale-pdf-engine-clone" @@ -242,7 +242,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ ############### module "printit_pdf_engine_app_service_java_clone" { source = "./.terraform/modules/__v3__/app_service" - count = var.is_feature_enabled.pdf_engine ? 1 : 0 + count = var.is_feature_enabled.pdf_engine_clone ? 1 : 0 vnet_integration = false resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name @@ -276,7 +276,7 @@ module "printit_pdf_engine_app_service_java_clone" { } module "printit_pdf_engine_java_slot_staging_clone" { - count = var.env_short != "d" && var.is_feature_enabled.pdf_engine ? 1 : 0 + count = var.env_short != "d" && var.is_feature_enabled.pdf_engine_clone ? 1 : 0 source = "./.terraform/modules/__v3__/app_service_slot" @@ -309,7 +309,7 @@ module "printit_pdf_engine_java_slot_staging_clone" { } resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_engine_java_autoscale_clone" { - count = var.env_short != "d" && var.is_feature_enabled.pdf_engine ? 1 : 0 + count = var.env_short != "d" && var.is_feature_enabled.pdf_engine_clone ? 1 : 0 name = "${local.project}-autoscale-pdf-engine-java-clone" diff --git a/src/domains/printit-app/04_apim_pdf_engine.tf b/src/domains/printit-app/04_apim_pdf_engine.tf index 128494910..acee0d16a 100644 --- a/src/domains/printit-app/04_apim_pdf_engine.tf +++ b/src/domains/printit-app/04_apim_pdf_engine.tf @@ -31,7 +31,7 @@ locals { description = "PDF Engine Service for Stampa Avvisi - API" path = "printit/pdf-engine" subscription_required = true - service_url = can(module.printit_pdf_engine_app_service_java[0].default_site_hostname) ? module.printit_pdf_engine_app_service_java[0].default_site_hostname : "" + service_url = var.is_feature_enabled.apim_use_pdf_engine_clone ? (can(module.printit_pdf_engine_app_service_java_clone[0].default_site_hostname) ? module.printit_pdf_engine_app_service_java_clone[0].default_site_hostname : "") : (can(module.printit_pdf_engine_app_service_java[0].default_site_hostname) ? module.printit_pdf_engine_app_service_java[0].default_site_hostname : "") } apim_pdf_engine_node_service_api = { # node @@ -39,7 +39,7 @@ locals { description = "PDF Engine Node Service for Stampa Avvisi - API" path = "printit/pdf-engine-node" subscription_required = true - service_url = can(module.printit_pdf_engine_app_service[0].default_site_hostname) ? module.printit_pdf_engine_app_service[0].default_site_hostname : "" + service_url = var.is_feature_enabled.apim_use_pdf_engine_clone ? (can(module.printit_pdf_engine_app_service_clone[0].default_site_hostname) ? module.printit_pdf_engine_app_service_clone[0].default_site_hostname : "") :(can(module.printit_pdf_engine_app_service[0].default_site_hostname) ? module.printit_pdf_engine_app_service[0].default_site_hostname : "") } } diff --git a/src/domains/printit-app/99_variables.tf b/src/domains/printit-app/99_variables.tf index db7a8f75f..ff7f259b8 100644 --- a/src/domains/printit-app/99_variables.tf +++ b/src/domains/printit-app/99_variables.tf @@ -73,10 +73,14 @@ variable "is_feature_enabled" { type = object({ pdf_engine = bool printit = bool + apim_use_pdf_engine_clone = optional(bool, false) + pdf_engine_clone = optional(bool, false) }) default = { pdf_engine = false printit = false + apim_use_pdf_engine_clone = false + pdf_engine_clone = false } } ### External resources @@ -223,3 +227,4 @@ variable "app_service_ip_restriction_default_action" { default = "Allow" description = "(Optional) The Default action for traffic that does not match any ip_restriction rule. possible values include Allow and Deny. Defaults to Allow." } + diff --git a/src/domains/printit-app/env/itn-prod/terraform.tfvars b/src/domains/printit-app/env/itn-prod/terraform.tfvars index 3bd0c7b6a..b817ee950 100644 --- a/src/domains/printit-app/env/itn-prod/terraform.tfvars +++ b/src/domains/printit-app/env/itn-prod/terraform.tfvars @@ -38,7 +38,9 @@ ingress_load_balancer_ip = "10.3.2.250" # pdf-engine is_feature_enabled = { pdf_engine = true + pdf_engine_clone = true printit = true + apim_use_pdf_engine_clone = false } app_service_pdf_engine_sku_name = "P2v3" From 91b7ce40cb4b09b48642cd9655aeadb620fdc884 Mon Sep 17 00:00:00 2001 From: mamari90 <130982006+mamari90@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:59:59 +0100 Subject: [PATCH 3/5] precommit --- src/domains/printit-app/04_apim_pdf_engine.tf | 2 +- src/domains/printit-app/99_variables.tf | 12 ++++++------ src/domains/printit-app/README.md | 8 +++++++- .../printit-app/env/itn-prod/terraform.tfvars | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/domains/printit-app/04_apim_pdf_engine.tf b/src/domains/printit-app/04_apim_pdf_engine.tf index acee0d16a..60de6096e 100644 --- a/src/domains/printit-app/04_apim_pdf_engine.tf +++ b/src/domains/printit-app/04_apim_pdf_engine.tf @@ -39,7 +39,7 @@ locals { description = "PDF Engine Node Service for Stampa Avvisi - API" path = "printit/pdf-engine-node" subscription_required = true - service_url = var.is_feature_enabled.apim_use_pdf_engine_clone ? (can(module.printit_pdf_engine_app_service_clone[0].default_site_hostname) ? module.printit_pdf_engine_app_service_clone[0].default_site_hostname : "") :(can(module.printit_pdf_engine_app_service[0].default_site_hostname) ? module.printit_pdf_engine_app_service[0].default_site_hostname : "") + service_url = var.is_feature_enabled.apim_use_pdf_engine_clone ? (can(module.printit_pdf_engine_app_service_clone[0].default_site_hostname) ? module.printit_pdf_engine_app_service_clone[0].default_site_hostname : "") : (can(module.printit_pdf_engine_app_service[0].default_site_hostname) ? module.printit_pdf_engine_app_service[0].default_site_hostname : "") } } diff --git a/src/domains/printit-app/99_variables.tf b/src/domains/printit-app/99_variables.tf index ff7f259b8..ae8f59e2a 100644 --- a/src/domains/printit-app/99_variables.tf +++ b/src/domains/printit-app/99_variables.tf @@ -71,16 +71,16 @@ variable "tags" { variable "is_feature_enabled" { type = object({ - pdf_engine = bool - printit = bool + pdf_engine = bool + printit = bool apim_use_pdf_engine_clone = optional(bool, false) - pdf_engine_clone = optional(bool, false) + pdf_engine_clone = optional(bool, false) }) default = { - pdf_engine = false - printit = false + pdf_engine = false + printit = false apim_use_pdf_engine_clone = false - pdf_engine_clone = false + pdf_engine_clone = false } } ### External resources diff --git a/src/domains/printit-app/README.md b/src/domains/printit-app/README.md index a649ffcd0..3bc33f63e 100644 --- a/src/domains/printit-app/README.md +++ b/src/domains/printit-app/README.md @@ -145,9 +145,13 @@ No outputs. | [kubernetes\_service\_account](#module\_kubernetes\_service\_account) | ./.terraform/modules/__v3__/kubernetes_service_account | n/a | | [pod\_identity](#module\_pod\_identity) | ./.terraform/modules/__v3__/kubernetes_pod_identity | n/a | | [printit\_pdf\_engine\_app\_service](#module\_printit\_pdf\_engine\_app\_service) | ./.terraform/modules/__v3__/app_service | n/a | +| [printit\_pdf\_engine\_app\_service\_clone](#module\_printit\_pdf\_engine\_app\_service\_clone) | ./.terraform/modules/__v3__/app_service | n/a | | [printit\_pdf\_engine\_app\_service\_java](#module\_printit\_pdf\_engine\_app\_service\_java) | ./.terraform/modules/__v3__/app_service | n/a | +| [printit\_pdf\_engine\_app\_service\_java\_clone](#module\_printit\_pdf\_engine\_app\_service\_java\_clone) | ./.terraform/modules/__v3__/app_service | n/a | | [printit\_pdf\_engine\_java\_slot\_staging](#module\_printit\_pdf\_engine\_java\_slot\_staging) | ./.terraform/modules/__v3__/app_service_slot | n/a | +| [printit\_pdf\_engine\_java\_slot\_staging\_clone](#module\_printit\_pdf\_engine\_java\_slot\_staging\_clone) | ./.terraform/modules/__v3__/app_service_slot | n/a | | [printit\_pdf\_engine\_slot\_staging](#module\_printit\_pdf\_engine\_slot\_staging) | ./.terraform/modules/__v3__/app_service_slot | n/a | +| [printit\_pdf\_engine\_slot\_staging\_clone](#module\_printit\_pdf\_engine\_slot\_staging\_clone) | ./.terraform/modules/__v3__/app_service_slot | n/a | | [tls\_checker](#module\_tls\_checker) | ./.terraform/modules/__v3__/tls_checker | n/a | ## Resources @@ -186,7 +190,9 @@ No outputs. | [azurerm_key_vault_secret.templates_storage_account_pkey](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource | | [azurerm_key_vault_secret.tenant_id](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) | resource | | [azurerm_monitor_autoscale_setting.autoscale_app_service_printit_pdf_engine_autoscale](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_autoscale_setting) | resource | +| [azurerm_monitor_autoscale_setting.autoscale_app_service_printit_pdf_engine_autoscale_clone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_autoscale_setting) | resource | | [azurerm_monitor_autoscale_setting.autoscale_app_service_printit_pdf_engine_java_autoscale](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_autoscale_setting) | resource | +| [azurerm_monitor_autoscale_setting.autoscale_app_service_printit_pdf_engine_java_autoscale_clone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_autoscale_setting) | resource | | [azurerm_monitor_scheduled_query_rules_alert.generate-pdf-engine-generate-responsetime](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource | | [azurerm_monitor_scheduled_query_rules_alert.pagopa-pdf-engine-pdf-availability](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource | | [azurerm_monitor_scheduled_query_rules_alert.pagopa-print-payment-notice-generator-responsetime-upd](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource | @@ -255,7 +261,7 @@ No outputs. | [ingress\_load\_balancer\_ip](#input\_ingress\_load\_balancer\_ip) | ## Aks | `string` | n/a | yes | | [instance](#input\_instance) | One of beta, prod01, prod02 | `string` | n/a | yes | | [io\_backend\_base\_path](#input\_io\_backend\_base\_path) | io backend api base path | `string` | `null` | no | -| [is\_feature\_enabled](#input\_is\_feature\_enabled) | n/a |
object({|
pdf_engine = bool
printit = bool
})
{| no | +| [is\_feature\_enabled](#input\_is\_feature\_enabled) | n/a |
"pdf_engine": false,
"printit": false
}
object({|
pdf_engine = bool
printit = bool
apim_use_pdf_engine_clone = optional(bool, false)
pdf_engine_clone = optional(bool, false)
})
{| no | | [k8s\_kube\_config\_path\_prefix](#input\_k8s\_kube\_config\_path\_prefix) | n/a | `string` | `"~/.kube"` | no | | [location](#input\_location) | One of westeurope, northeurope | `string` | n/a | yes | | [location\_short](#input\_location\_short) | One of wue, neu | `string` | n/a | yes | diff --git a/src/domains/printit-app/env/itn-prod/terraform.tfvars b/src/domains/printit-app/env/itn-prod/terraform.tfvars index b817ee950..b5915fee1 100644 --- a/src/domains/printit-app/env/itn-prod/terraform.tfvars +++ b/src/domains/printit-app/env/itn-prod/terraform.tfvars @@ -37,9 +37,9 @@ ingress_load_balancer_ip = "10.3.2.250" # pdf-engine is_feature_enabled = { - pdf_engine = true - pdf_engine_clone = true - printit = true + pdf_engine = true + pdf_engine_clone = true + printit = true apim_use_pdf_engine_clone = false } From a356421629b532baa3ca25a3c56c7e82f3e52945 Mon Sep 17 00:00:00 2001 From: mamari90 <130982006+mamari90@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:28:52 +0100 Subject: [PATCH 4/5] prepared shared pdf engine non-ha --- .../shared-app/01_app_service_pdf_engine.tf | 14 +++++++------- src/domains/shared-app/04_apim_pdf_engine.tf | 4 ++-- src/domains/shared-app/99_variables.tf | 6 ++++++ src/domains/shared-app/README.md | 1 + .../shared-app/env/weu-prod/terraform.tfvars | 1 + 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/domains/shared-app/01_app_service_pdf_engine.tf b/src/domains/shared-app/01_app_service_pdf_engine.tf index bc42d95a0..05db95584 100644 --- a/src/domains/shared-app/01_app_service_pdf_engine.tf +++ b/src/domains/shared-app/01_app_service_pdf_engine.tf @@ -21,7 +21,7 @@ moved { resource "azurerm_resource_group" "shared_pdf_engine_app_service_rg" { - count = var.env_short != "p" ? 1 : 0 # only DEV and UAT + count = 1 name = format("%s-pdf-engine-rg", local.project) location = var.location @@ -38,7 +38,7 @@ data "azurerm_container_registry" "container_registry" { ################ module "shared_pdf_engine_app_service" { - count = var.env_short != "p" ? 1 : 0 # only DEV and UAT + count = 1 source = "./.terraform/modules/__v3__/app_service" vnet_integration = false @@ -72,7 +72,7 @@ module "shared_pdf_engine_app_service" { } module "shared_pdf_engine_slot_staging" { - count = var.env_short == "u" ? 1 : 0 + count = var.env_short != "d" ? 1 : 0 source = "./.terraform/modules/__v3__/app_service_slot" @@ -102,7 +102,7 @@ module "shared_pdf_engine_slot_staging" { } resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_shared_pdf_engine_autoscale" { - count = var.env_short == "u" ? 1 : 0 + count = var.env_short != "d" ? 1 : 0 name = format("%s-autoscale-pdf-engine", local.project) resource_group_name = azurerm_resource_group.shared_pdf_engine_app_service_rg[0].name @@ -270,7 +270,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_shared_pdf_e ################ module "shared_pdf_engine_app_service_java" { source = "./.terraform/modules/__v3__/app_service" - count = var.env_short != "p" ? 1 : 0 # only DEV and UAT + count = 1 vnet_integration = false resource_group_name = azurerm_resource_group.shared_pdf_engine_app_service_rg[0].name location = var.location @@ -302,7 +302,7 @@ module "shared_pdf_engine_app_service_java" { } module "shared_pdf_engine_java_slot_staging" { - count = var.env_short == "u" ? 1 : 0 + count = var.env_short != "d" ? 1 : 0 source = "./.terraform/modules/__v3__/app_service_slot" @@ -334,7 +334,7 @@ module "shared_pdf_engine_java_slot_staging" { } resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_shared_pdf_engine_java_autoscale" { - count = var.env_short == "u" ? 1 : 0 + count = var.env_short != "d" ? 1 : 0 name = format("%s-autoscale-pdf-engine-java", local.project) resource_group_name = azurerm_resource_group.shared_pdf_engine_app_service_rg[0].name diff --git a/src/domains/shared-app/04_apim_pdf_engine.tf b/src/domains/shared-app/04_apim_pdf_engine.tf index d63397912..3dc81dc9e 100644 --- a/src/domains/shared-app/04_apim_pdf_engine.tf +++ b/src/domains/shared-app/04_apim_pdf_engine.tf @@ -29,14 +29,14 @@ locals { description = "PDF Engine Service pagoPA - API" path = "shared/pdf-engine" subscription_required = true - service_url = var.pdf_engine_app_ha_enabled ? module.shared_pdf_engine_app_service_java_ha[0].default_site_hostname : module.shared_pdf_engine_app_service_java[0].default_site_hostname + service_url = var.apim_use_pdf_engine_app_ha ? module.shared_pdf_engine_app_service_java_ha[0].default_site_hostname : module.shared_pdf_engine_app_service_java[0].default_site_hostname } apim_pdf_engine_node_service_api = { # node display_name = "PDF Engine Node Service pagoPA - API" description = "PDF Engine Node Service pagoPA - API" path = "shared/pdf-engine-node" subscription_required = true - service_url = var.pdf_engine_app_ha_enabled ? module.shared_pdf_engine_app_service_ha[0].default_site_hostname : module.shared_pdf_engine_app_service[0].default_site_hostname + service_url = var.apim_use_pdf_engine_app_ha ? module.shared_pdf_engine_app_service_ha[0].default_site_hostname : module.shared_pdf_engine_app_service[0].default_site_hostname } } diff --git a/src/domains/shared-app/99_variables.tf b/src/domains/shared-app/99_variables.tf index 1a00929ef..d1c5a748c 100644 --- a/src/domains/shared-app/99_variables.tf +++ b/src/domains/shared-app/99_variables.tf @@ -305,6 +305,12 @@ variable "pdf_engine_app_ha_enabled" { description = "(Required) enables the deployment of pdf engine in HA mode" } +variable "apim_use_pdf_engine_app_ha" { + type = bool + description = "(Optional) enables the usage of pdf engine in HA mode" + default = false +} + // wallet session token variable "io_backend_base_path" { type = string diff --git a/src/domains/shared-app/README.md b/src/domains/shared-app/README.md index 2c2f625e8..e1cfb2b61 100644 --- a/src/domains/shared-app/README.md +++ b/src/domains/shared-app/README.md @@ -163,6 +163,7 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [apim\_dns\_zone\_prefix](#input\_apim\_dns\_zone\_prefix) | The dns subdomain for apim. | `string` | `null` | no | +| [apim\_use\_pdf\_engine\_app\_ha](#input\_apim\_use\_pdf\_engine\_app\_ha) | (Optional) enables the usage of pdf engine in HA mode | `bool` | `false` | no | | [app\_service\_pdf\_engine\_always\_on](#input\_app\_service\_pdf\_engine\_always\_on) | Always on property | `bool` | `true` | no | | [app\_service\_pdf\_engine\_autoscale\_enabled](#input\_app\_service\_pdf\_engine\_autoscale\_enabled) | n/a | `bool` | `true` | no | | [app\_service\_pdf\_engine\_sku\_name](#input\_app\_service\_pdf\_engine\_sku\_name) | app service plan size | `string` | `"S1"` | no | diff --git a/src/domains/shared-app/env/weu-prod/terraform.tfvars b/src/domains/shared-app/env/weu-prod/terraform.tfvars index ecba144dd..1010386a0 100644 --- a/src/domains/shared-app/env/weu-prod/terraform.tfvars +++ b/src/domains/shared-app/env/weu-prod/terraform.tfvars @@ -92,6 +92,7 @@ pagopa_shared_toolbox_enabled = false robots_indexed_paths = [] pdf_engine_app_ha_enabled = true pdf_engine_zone_balancing_enabled = true +apim_use_pdf_engine_app_ha = true // wallet session token io_backend_base_path = "https://api-app.io.pagopa.it" From c2bae4a19cdd16e07b7cecb0b603dfe8a940fcbc Mon Sep 17 00:00:00 2001 From: mamari90 <130982006+mamari90@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:47:58 +0100 Subject: [PATCH 5/5] added printit rg --- .../01_app_service_pdf_engine_clone.tf | 48 +++++++++++-------- src/domains/printit-app/README.md | 1 + .../shared-app/01_app_service_pdf_engine.tf | 6 +-- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/domains/printit-app/01_app_service_pdf_engine_clone.tf b/src/domains/printit-app/01_app_service_pdf_engine_clone.tf index e6733c497..9854bfc53 100644 --- a/src/domains/printit-app/01_app_service_pdf_engine_clone.tf +++ b/src/domains/printit-app/01_app_service_pdf_engine_clone.tf @@ -1,3 +1,11 @@ +resource "azurerm_resource_group" "printit_pdf_engine_app_service_rg_clone" { + count = var.is_feature_enabled.pdf_engine_clone ? 1 : 0 + name = "${local.project}-pdf-engine-clone-rg" + location = var.location + + tags = var.tags +} + ################ # node ################ @@ -8,7 +16,7 @@ module "printit_pdf_engine_app_service_clone" { count = var.is_feature_enabled.pdf_engine_clone ? 1 : 0 vnet_integration = false - resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg_clone[0].name location = var.location # App service plan vars @@ -52,7 +60,7 @@ module "printit_pdf_engine_slot_staging_clone" { # App service name = "staging" - resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg_clone[0].name location = var.location always_on = true @@ -78,8 +86,8 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ enabled = var.app_service_pdf_engine_autoscale_enabled name = "${local.project}-autoscale-pdf-engine-clone" - resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name - location = azurerm_resource_group.printit_pdf_engine_app_service_rg.location + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg_clone[0].name + location = azurerm_resource_group.printit_pdf_engine_app_service_rg_clone[0].location target_resource_id = module.printit_pdf_engine_app_service_clone[0].plan_id profile { @@ -95,7 +103,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "Requests" - metric_resource_id = module.printit_pdf_engine_app_service[0].id + metric_resource_id = module.printit_pdf_engine_app_service_clone[0].id metric_namespace = "microsoft.web/sites" time_grain = "PT1M" statistic = "Average" @@ -117,7 +125,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "Requests" - metric_resource_id = module.printit_pdf_engine_app_service[0].id + metric_resource_id = module.printit_pdf_engine_app_service_clone[0].id metric_namespace = "microsoft.web/sites" time_grain = "PT1M" statistic = "Average" @@ -143,7 +151,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "HttpResponseTime" - metric_resource_id = module.printit_pdf_engine_app_service[0].id + metric_resource_id = module.printit_pdf_engine_app_service_clone[0].id metric_namespace = "microsoft.web/sites" time_grain = "PT1M" statistic = "Average" @@ -165,7 +173,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "HttpResponseTime" - metric_resource_id = module.printit_pdf_engine_app_service[0].id + metric_resource_id = module.printit_pdf_engine_app_service_clone[0].id metric_namespace = "microsoft.web/sites" time_grain = "PT1M" statistic = "Average" @@ -191,7 +199,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "CpuPercentage" - metric_resource_id = module.printit_pdf_engine_app_service[0].plan_id + metric_resource_id = module.printit_pdf_engine_app_service_clone[0].plan_id metric_namespace = "microsoft.web/serverfarms" time_grain = "PT1M" statistic = "Average" @@ -213,7 +221,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "CpuPercentage" - metric_resource_id = module.printit_pdf_engine_app_service[0].plan_id + metric_resource_id = module.printit_pdf_engine_app_service_clone[0].plan_id metric_namespace = "microsoft.web/serverfarms" time_grain = "PT1M" statistic = "Average" @@ -245,7 +253,7 @@ module "printit_pdf_engine_app_service_java_clone" { count = var.is_feature_enabled.pdf_engine_clone ? 1 : 0 vnet_integration = false - resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg_clone[0].name location = var.location # App service plan vars @@ -287,7 +295,7 @@ module "printit_pdf_engine_java_slot_staging_clone" { # App service name = "staging" - resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg_clone[0].name location = var.location always_on = true @@ -313,8 +321,8 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ name = "${local.project}-autoscale-pdf-engine-java-clone" - resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg.name - location = azurerm_resource_group.printit_pdf_engine_app_service_rg.location + resource_group_name = azurerm_resource_group.printit_pdf_engine_app_service_rg_clone[0].name + location = azurerm_resource_group.printit_pdf_engine_app_service_rg_clone[0].location target_resource_id = module.printit_pdf_engine_app_service_java_clone[0].plan_id enabled = var.app_service_pdf_engine_autoscale_enabled @@ -331,7 +339,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "Requests" - metric_resource_id = module.printit_pdf_engine_app_service_java[0].id + metric_resource_id = module.printit_pdf_engine_app_service_java_clone[0].id metric_namespace = "microsoft.web/sites" time_grain = "PT1M" statistic = "Average" @@ -353,7 +361,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "Requests" - metric_resource_id = module.printit_pdf_engine_app_service_java[0].id + metric_resource_id = module.printit_pdf_engine_app_service_java_clone[0].id metric_namespace = "microsoft.web/sites" time_grain = "PT1M" statistic = "Average" @@ -379,7 +387,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "HttpResponseTime" - metric_resource_id = module.printit_pdf_engine_app_service_java[0].id + metric_resource_id = module.printit_pdf_engine_app_service_java_clone[0].id metric_namespace = "microsoft.web/sites" time_grain = "PT1M" statistic = "Average" @@ -401,7 +409,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "HttpResponseTime" - metric_resource_id = module.printit_pdf_engine_app_service_java[0].id + metric_resource_id = module.printit_pdf_engine_app_service_java_clone[0].id metric_namespace = "microsoft.web/sites" time_grain = "PT1M" statistic = "Average" @@ -427,7 +435,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "CpuPercentage" - metric_resource_id = module.printit_pdf_engine_app_service_java[0].plan_id + metric_resource_id = module.printit_pdf_engine_app_service_java_clone[0].plan_id metric_namespace = "microsoft.web/serverfarms" time_grain = "PT1M" statistic = "Average" @@ -449,7 +457,7 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_printit_pdf_ rule { metric_trigger { metric_name = "CpuPercentage" - metric_resource_id = module.printit_pdf_engine_app_service_java[0].plan_id + metric_resource_id = module.printit_pdf_engine_app_service_java_clone[0].plan_id metric_namespace = "microsoft.web/serverfarms" time_grain = "PT1M" statistic = "Average" diff --git a/src/domains/printit-app/README.md b/src/domains/printit-app/README.md index 3bc33f63e..3efa080e8 100644 --- a/src/domains/printit-app/README.md +++ b/src/domains/printit-app/README.md @@ -206,6 +206,7 @@ No outputs. | [azurerm_monitor_scheduled_query_rules_alert.print-notice-retry-fn-error-alert](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource | | [azurerm_private_dns_a_record.ingress](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_a_record) | resource | | [azurerm_resource_group.printit_pdf_engine_app_service_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource | +| [azurerm_resource_group.printit_pdf_engine_app_service_rg_clone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource | | [helm_release.cert_mounter](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | | [helm_release.reloader](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | | [kubernetes_namespace.namespace](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource | diff --git a/src/domains/shared-app/01_app_service_pdf_engine.tf b/src/domains/shared-app/01_app_service_pdf_engine.tf index 05db95584..d5d02d01d 100644 --- a/src/domains/shared-app/01_app_service_pdf_engine.tf +++ b/src/domains/shared-app/01_app_service_pdf_engine.tf @@ -114,9 +114,9 @@ resource "azurerm_monitor_autoscale_setting" "autoscale_app_service_shared_pdf_e name = "default" capacity { - default = 1 - minimum = 1 - maximum = 1 + default = var.env_short == "p" ? 3 : 1 + minimum = var.env_short == "p" ? 3 : 1 + maximum = var.env_short == "p" ? 12 : 1 } # Requests
"apim_use_pdf_engine_clone": false,
"pdf_engine": false,
"pdf_engine_clone": false,
"printit": false
}