diff --git a/infra/modules/azure_function_app/README.md b/infra/modules/azure_function_app/README.md index 90d2c7707..8e0642b9b 100644 --- a/infra/modules/azure_function_app/README.md +++ b/infra/modules/azure_function_app/README.md @@ -12,7 +12,7 @@ | Name | Version | |------|---------| -| [azurerm](#provider\_azurerm) | 3.104.0 | +| [azurerm](#provider\_azurerm) | 3.107.0 | ## Modules diff --git a/infra/modules/azure_function_app/function_app.tf b/infra/modules/azure_function_app/function_app.tf index 899833eb3..05c9da6a8 100644 --- a/infra/modules/azure_function_app/function_app.tf +++ b/infra/modules/azure_function_app/function_app.tf @@ -1,5 +1,5 @@ resource "azurerm_linux_function_app" "this" { - name = "${local.project}-${var.environment.domain}-${var.environment.app_name}-func-${var.environment.instance_number}" + name = local.function_app.name location = var.environment.location resource_group_name = var.resource_group_name @@ -43,6 +43,8 @@ resource "azurerm_linux_function_app" "this" { # https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference?tabs=blob&pivots=programming-language-csharp#connecting-to-host-storage-with-an-identity SLOT_TASK_HUBNAME = "ProductionTaskHub", }, + # https://learn.microsoft.com/en-us/azure/azure-functions/errors-diagnostics/diagnostic-events/azfd0004#options-for-addressing-collisions + length(local.function_app.name) > 32 ? { AzureFunctionsWebHost__hostid = "production" } : {}, var.app_settings, local.application_insights.enable ? { # https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling @@ -55,6 +57,7 @@ resource "azurerm_linux_function_app" "this" { [ "SLOT_TASK_HUBNAME", ], + length(local.function_app.name) > 32 ? ["AzureFunctionsWebHost__hostid"] : [], var.sticky_app_setting_names, ) } diff --git a/infra/modules/azure_function_app/function_app_slot.tf b/infra/modules/azure_function_app/function_app_slot.tf index f8b9f11d3..3da45892a 100644 --- a/infra/modules/azure_function_app/function_app_slot.tf +++ b/infra/modules/azure_function_app/function_app_slot.tf @@ -1,7 +1,7 @@ resource "azurerm_linux_function_app_slot" "this" { count = local.function_app.is_slot_enabled - name = "staging" + name = local.function_app_slot.name function_app_id = azurerm_linux_function_app.this.id storage_account_name = azurerm_storage_account.this.name @@ -44,6 +44,8 @@ resource "azurerm_linux_function_app_slot" "this" { # https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference?tabs=blob&pivots=programming-language-csharp#connecting-to-host-storage-with-an-identity SLOT_TASK_HUBNAME = "StagingTaskHub", }, + # https://learn.microsoft.com/en-us/azure/azure-functions/errors-diagnostics/diagnostic-events/azfd0004#options-for-addressing-collisions + length("${azurerm_linux_function_app.this.name}-${local.function_app_slot.name}") > 32 ? { AzureFunctionsWebHost__hostid = local.function_app_slot.name } : {}, var.slot_app_settings ) diff --git a/infra/modules/azure_function_app/locals.tf b/infra/modules/azure_function_app/locals.tf index 5a5aec008..8375c4088 100644 --- a/infra/modules/azure_function_app/locals.tf +++ b/infra/modules/azure_function_app/locals.tf @@ -7,11 +7,16 @@ locals { } function_app = { + name = "${local.project}-${var.environment.domain}-${var.environment.app_name}-func-${var.environment.instance_number}" sku_name = var.tier == "test" ? "B1" : var.tier == "standard" ? "P0v3" : "P1v3" zone_balancing_enabled = var.tier != "test" is_slot_enabled = var.tier == "test" ? 0 : 1 } + function_app_slot = { + name = "staging" + } + application_insights = { enable = var.application_insights_connection_string != null }