I am trying to link an existing Azure function to a static web app using Terraform and FastAPI. Provisioning and deployment in devops works fine, but the URL is not working properly.
When I request the function app URL https://func-***.azurewebsites.net/api/v1/ping
, I get the following error:
{"code":400,"message":"Login not supported for provider azureStaticWebApps"}
When I request the API path in the static web app URL https://***.azurestaticapps.net/api/v1/ping
, I get a 404 Not Found.
I am not sure how to debug this, running the function locally works fine.
This is my Terraform code:
// Create a linux function app
resource "azurerm_linux_function_app" "this" {
name = "func-${var.organization}-${var.application}-${var.environment}"
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
service_plan_id = azurerm_service_plan.this.id
storage_account_name = azurerm_storage_account.function.name
storage_account_access_key = azurerm_storage_account.function.primary_access_key
identity {
type = "SystemAssigned"
}
site_config {
always_on = true
application_insights_key = azurerm_application_insights.this.instrumentation_key
application_stack {
python_version = "3.11"
}
}
app_settings = {
"SCM_DO_BUILD_DURING_DEPLOYMENT" = "true"
"URL_BASE" = "https://${azurerm_static_web_app.this.default_host_name}"
"URL_BASE_API" = "https://${azurerm_static_web_app.this.default_host_name}/api"
}
tags = local.tags
lifecycle {
ignore_changes = [auth_settings_v2]
}
}
// Create static web app
resource "azurerm_static_web_app" "this" {
name = "app-${var.organization}-${var.application}-${var.environment}"
resource_group_name = azurerm_resource_group.this.name
location = azurerm_resource_group.this.location
sku_tier = "Standard"
sku_size = "Standard"
}
// Register the function as API to the static web app
resource "azurerm_static_web_app_function_app_registration" "this" {
static_web_app_id = azurerm_static_web_app.this.id
function_app_id = azurerm_linux_function_app.this.id
}
This is my function code:
import azure.functions as func
import fastapi
fastapi_app = fastapi.FastAPI(root_path="/api/v1")
@fastapi_app.get("/ping")
async def index():
return "pong"
app = func.AsgiFunctionApp(
app=fastapi_app,
http_auth_level=func.AuthLevel.ANONYMOUS
)
The routePrefix
in my host.json
is an empty string. Any ideas on how to solve this?