We are experiencing an issue when deploying Azure Function app's via Terraform.
When deploying an Azure Function to an App Service Plan, there are two erroneous application settings being added by default.
They are:
According to Microsoft Docs, these should only be set on Consumption Plan function apps.
Weirdly, those app settings have been there since the resource was included, but it's now causing major issues in Azure. If those settings are removed (say on a deployment that sets other app settings), it causes the backend function runtime to explode and render the entire function app useless.
Terraform v0.11.7
resource "azurerm_app_service_plan" "app_plan" {
name = "${var.name}"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
tags = "${var.tags}"
sku {
tier = "Standard"
size = "S2"
}
}
resource "azurerm_function_app" "function_apps" {
name = "${var.name}"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
app_service_plan_id = "${azurerm_app_service_plan.app_plan.id}"
storage_connection_string = "${var.storage_account_connection_string}"
version = "~1"
tags = "${var.tags}"
site_config {
always_on = "${var.always_on}"
}
}
Note: This is not our exact code as I've got it split into modules etc, but the correct properties are set
Ideally, these two properties would only be set when creating a consumption app, although I'm not 100% sure that would be checked considering it's the app service plan that dictates if it's consumption...
A app service plan function app is created with those two application settings set
terraform applyI'm happy give this fix a go, I'm just not sure how to best represent the fix. Ideally, the app service type + sku would dictate if the app settings are set, but I'm not sure if there is a precedent for checking linked resources when building a resource (any examples would be great).
Otherwise, a property on the function_app resource to specify if it's consumption or not seems like the only other way go.
That fix will not work because it blocks you from properly deploying a Consumption plan application where these settings are needed. The easiest way to do this is by only adding these settings if the plan is set to "Dynamic".
Edit: problem is though that you do not have that info in the function app as it is part of the app service plan and you only got the id of that. Only way that would be solvable is by pulling the app service plan first and then building the function app create. @tombuildsstuff or @katbyte thoughts on that?
Yeah, that fix was strictly a fix for us so we could get through the issues we were having (it was completely stopping testing). I linked it just in case someone else might want it. I intend to update it with the appropriate fix once the issue you identified has been decided.
@ranieuwe @tombuildsstuff @katbyte Do you know of any existing resources that pull info from a previous resource before it creates itself?
@APErebus @ranieuwe I believe we do this for some of the ServiceBus resources, in this case I guess we'd have to look up the containing App Service and assume that it having a SKU of Dynamic was a consumption plan, and omitting the fields that way?
@tombuildsstuff exactly my train of thought. I already have most of the code ready. Will make a PR in the next few days.
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!