Skip to content

Commit

Permalink
[IOPID-2510 - Step 1] Remove shared plan from state (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
gquadrati authored Jan 20, 2025
1 parent a69f85f commit 7bc4daa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 180 deletions.
4 changes: 2 additions & 2 deletions src/domains/citizen-auth-app/01_network_itn.tf
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ resource "azurerm_private_endpoint" "staging_function_profile_async_itn_sites" {
resource "azurerm_private_endpoint" "function_public_itn_sites" {
name = "${local.common_project_itn}-public-func-pep-01"
location = local.itn_location
resource_group_name = azurerm_resource_group.shared_rg_itn.name
resource_group_name = format("%s-shared-rg-01", local.project_itn)
subnet_id = data.azurerm_subnet.itn_pep.id

private_service_connection {
Expand All @@ -182,7 +182,7 @@ resource "azurerm_private_endpoint" "function_public_itn_sites" {
resource "azurerm_private_endpoint" "staging_function_public_itn_sites" {
name = "${local.common_project_itn}-fast-login-func-staging-pep-01"
location = local.itn_location
resource_group_name = azurerm_resource_group.shared_rg_itn.name
resource_group_name = format("%s-shared-rg-01", local.project_itn)
subnet_id = data.azurerm_subnet.itn_pep.id

private_service_connection {
Expand Down
21 changes: 2 additions & 19 deletions src/domains/citizen-auth-app/04_shared_plan.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
resource "azurerm_resource_group" "shared_rg_itn" {
name = format("%s-shared-rg-01", local.project_itn)
location = local.itn_location
}

resource "azurerm_app_service_plan" "shared_plan_itn" {
data "azurerm_app_service_plan" "shared_plan_itn" {
name = format("%s-shared-asp-01", local.project_itn)
location = azurerm_resource_group.shared_rg_itn.location
resource_group_name = azurerm_resource_group.shared_rg_itn.name

kind = var.plan_shared_1_kind
reserved = true

sku {
tier = var.plan_shared_1_sku_tier
size = var.plan_shared_1_sku_size
capacity = var.plan_shared_1_sku_capacity
}

tags = var.tags
resource_group_name = format("%s-shared-rg-01", local.project_itn)
}

# Subnet to host app function
Expand Down
159 changes: 5 additions & 154 deletions src/domains/citizen-auth-app/10_function_public.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ locals {

module "function_public_itn" {
source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//function_app?ref=v8.44.0"
depends_on = [azurerm_app_service_plan.shared_plan_itn, module.shared_snet_itn]
depends_on = [module.shared_snet_itn]

resource_group_name = azurerm_resource_group.shared_rg_itn.name
resource_group_name = format("%s-shared-rg-01", local.project_itn)
name = format("%s-public-func-01", local.short_project_itn)
location = local.itn_location
domain = "auth"
Expand All @@ -45,7 +45,7 @@ module "function_public_itn" {
node_version = "20"
runtime_version = "~4"

app_service_plan_id = azurerm_app_service_plan.shared_plan_itn.id
app_service_plan_id = data.azurerm_app_service_plan.shared_plan_itn.id

always_on = "true"
application_insights_instrumentation_key = data.azurerm_application_insights.application_insights.instrumentation_key
Expand Down Expand Up @@ -83,11 +83,11 @@ module "function_public_itn" {

module "function_public_staging_slot_itn" {
source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//function_app_slot?ref=v8.44.0"
depends_on = [azurerm_app_service_plan.shared_plan_itn, module.shared_snet_itn]
depends_on = [module.shared_snet_itn]

name = "staging"
location = local.itn_location
resource_group_name = azurerm_resource_group.shared_rg_itn.name
resource_group_name = format("%s-shared-rg-01", local.project_itn)
function_app_id = module.function_public_itn.id
app_service_plan_id = module.function_public_itn.app_service_plan_id
health_check_path = "/info"
Expand All @@ -112,152 +112,3 @@ module "function_public_staging_slot_itn" {

tags = var.tags
}

resource "azurerm_monitor_autoscale_setting" "function_public_itn" {
name = format("%s-autoscale", module.function_public_itn.name)
resource_group_name = azurerm_resource_group.shared_rg_itn.name
location = local.itn_location
target_resource_id = module.function_public_itn.app_service_plan_id

profile {
name = "default"

capacity {
default = var.function_public_autoscale_default
minimum = var.function_public_autoscale_minimum
maximum = var.function_public_autoscale_maximum
}

rule {
metric_trigger {
metric_name = "Requests"
metric_resource_id = module.function_public_itn.id
metric_namespace = "microsoft.web/sites"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "GreaterThan"
threshold = 3000
divide_by_instance_count = false
}

scale_action {
direction = "Increase"
type = "ChangeCount"
value = "2"
cooldown = "PT5M"
}
}

rule {
metric_trigger {
metric_name = "Requests"
metric_resource_id = data.azurerm_linux_function_app.function_web_profile.id
metric_namespace = "microsoft.web/sites"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "GreaterThan"
threshold = 3000
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.function_public_itn.app_service_plan_id
metric_namespace = "microsoft.web/serverfarms"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "GreaterThan"
threshold = 45
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.function_public_itn.id
metric_namespace = "microsoft.web/sites"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "LessThan"
threshold = 2000
divide_by_instance_count = false
}

scale_action {
direction = "Decrease"
type = "ChangeCount"
value = "1"
cooldown = "PT20M"
}
}

rule {
metric_trigger {
metric_name = "Requests"
metric_resource_id = data.azurerm_linux_function_app.function_web_profile.id
metric_namespace = "microsoft.web/sites"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "LessThan"
threshold = 2000
divide_by_instance_count = false
}

scale_action {
direction = "Decrease"
type = "ChangeCount"
value = "1"
cooldown = "PT20M"
}
}

rule {
metric_trigger {
metric_name = "CpuPercentage"
metric_resource_id = module.function_public_itn.app_service_plan_id
metric_namespace = "microsoft.web/serverfarms"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "LessThan"
threshold = 30
divide_by_instance_count = false
}

scale_action {
direction = "Decrease"
type = "ChangeCount"
value = "1"
cooldown = "PT20M"
}
}
}
}
4 changes: 1 addition & 3 deletions src/domains/citizen-auth-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@

| Name | Type |
|------|------|
| [azurerm_app_service_plan.shared_plan_itn](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_plan) | resource |
| [azurerm_monitor_autoscale_setting.function_profile](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_autoscale_setting) | resource |
| [azurerm_monitor_autoscale_setting.function_profile_async](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_autoscale_setting) | resource |
| [azurerm_monitor_autoscale_setting.function_public_itn](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_autoscale_setting) | resource |
| [azurerm_monitor_metric_alert.function_profile_async_health_check](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_metric_alert) | resource |
| [azurerm_monitor_metric_alert.function_profile_health_check](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_metric_alert) | resource |
| [azurerm_monitor_scheduled_query_rules_alert_v2.samlresponse_missing_detection_alert](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert_v2) | resource |
Expand All @@ -61,13 +59,13 @@
| [azurerm_resource_group.function_profile_async_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
| [azurerm_resource_group.function_profile_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
| [azurerm_resource_group.session_manager_rg_weu](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
| [azurerm_resource_group.shared_rg_itn](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
| [azurerm_storage_table.locked_profiles](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_table) | resource |
| [azurerm_subnet_nat_gateway_association.session_manager_snet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_nat_gateway_association) | resource |
| [azuread_group.adgroup_admin](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/group) | data source |
| [azuread_group.adgroup_developers](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/group) | data source |
| [azuread_group.adgroup_externals](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/group) | data source |
| [azuread_group.adgroup_security](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/group) | data source |
| [azurerm_app_service_plan.shared_plan_itn](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/app_service_plan) | data source |
| [azurerm_application_gateway.app_gateway](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/application_gateway) | data source |
| [azurerm_application_insights.application_insights](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/application_insights) | data source |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) | data source |
Expand Down
20 changes: 20 additions & 0 deletions src/domains/citizen-auth-app/removed.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
removed {
from = azurerm_resource_group.shared_rg_itn
lifecycle {
destroy = false
}
}

removed {
from = azurerm_app_service_plan.shared_plan_itn
lifecycle {
destroy = false
}
}

removed {
from = azurerm_monitor_autoscale_setting.function_public_itn
lifecycle {
destroy = false
}
}
2 changes: 0 additions & 2 deletions src/domains/ioweb-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ No modules.
| [azurerm_subnet.apim_itn_snet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
| [azurerm_subnet.apim_v2_snet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
| [azurerm_subnet.azdoa_snet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
| [azurerm_subnet.function_profile_snet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
| [azurerm_subnet.private_endpoints_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |
| [azurerm_subscription.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscription) | data source |
| [azurerm_virtual_network.common_vnet_italy_north](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/virtual_network) | data source |
| [azurerm_virtual_network.vnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/virtual_network) | data source |
| [azurerm_virtual_network.vnet_common](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/virtual_network) | data source |

Expand Down

0 comments on commit 7bc4daa

Please sign in to comment.