Skip to content

Commit

Permalink
Fix function app slot host id collision (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-calabrese authored Jun 7, 2024
1 parent c146916 commit 394638f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion infra/modules/azure_function_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.104.0 |
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.107.0 |

## Modules

Expand Down
5 changes: 4 additions & 1 deletion infra/modules/azure_function_app/function_app.tf
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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,
)
}
Expand Down
4 changes: 3 additions & 1 deletion infra/modules/azure_function_app/function_app_slot.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)

Expand Down
5 changes: 5 additions & 0 deletions infra/modules/azure_function_app/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 394638f

Please sign in to comment.