terraform-provider-azurerm
terraform-provider-azurerm copied to clipboard
Support for setting CURRENT_STACK for Azure Functions, enabling durable Azure Functions on PowerShell
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Description
I am trying to create a azurerm_function_app with PowerShell 7 based durable Azure Functions. When the function app is created, the following setting is blank, which makes the durable functions return 500 internal server error:
New or Affected Resource(s)
- azurerm_function_app
Potential Terraform Configuration
It seems that behind the scenes for the Azure Portal, the following is sent when updating the blank field to PowerShell 7.0 (as a part of siteConfig):
"metadata": [
{
"name": "CURRENT_STACK",
"value": "powershell"
}
]
resource "azurerm_function_app" "function" {
name = "superfunction"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
app_service_plan_id = azurerm_app_service_plan.function_plan.id
storage_account_name = azurerm_storage_account.function_storage.name
storage_account_access_key = azurerm_storage_account.function_storage.primary_access_key
version = "~3"
https_only = true
app_settings = {
ApplicationInsightsAgent_EXTENSION_VERSION = "~2"
FUNCTIONS_WORKER_RUNTIME = "powershell"
FUNCTION_APP_EDIT_MODE = "readonly"
WEBSITE_NODE_DEFAULT_VERSION = "10.14.1"
}
identity {
type = "SystemAssigned"
}
site_config {
metadata = [
{
name = "CURRENT_STACK"
value = "powershell"
}
]
}
}
References
I also have to manually update that PowerShell Core Version setting, and restart the function app to make it work, so looking forward to this fix.
I've seen other people define siteConfig.powerShellVersion = "~7"
, eg: https://github.com/neumanndaniel/armtemplates/blob/aa14255f3a2be592ac60dc8ff541fda7cb10c649/aks-snapshot-backup/aks-snapshot-backup-infrastructure.json#L97
Hi I am facing the same issue with Terraform. I am trying to create a Powershell Function App in Azure with azurerm_function_app and I want to set Powershell Core Version to 7. The issue is that after terraform apply the Function App is created, but the Powershell Core Version is blank. I was able to set the Python version for a Linux Function App, but not for Powershell.
I tried something like that, but with no success:
resource "azurerm_function_app" "example" {
name = "functionapptest"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
version = "~3"
app_settings = {
FUNCTIONS_WORKER_RUNTIME = "powershell"
FUNCTIONS_WORKER_RUNTIME_VERSION = "~7"
}
}
I know that in a Linux Function App you can set the the Python version using:
site_config {
linux_fx_version = "PYTHON|3.9"
}
Is there any update on this issue?
I would like to know how to do this too
Hi I am facing the same issue with Terraform. I am trying to create a Powershell Function App in Azure with azurerm_function_app and I want to set Powershell Core Version to 7. The issue is that after terraform apply the Function App is created, but the Powershell Core Version is blank. I was able to set the Python version for a Linux Function App, but not for Powershell.
I tried something like that, but with no success:
resource "azurerm_function_app" "example" { name = "functionapptest" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name app_service_plan_id = azurerm_app_service_plan.example.id storage_account_name = azurerm_storage_account.example.name storage_account_access_key = azurerm_storage_account.example.primary_access_key version = "~3" app_settings = { FUNCTIONS_WORKER_RUNTIME = "powershell" FUNCTIONS_WORKER_RUNTIME_VERSION = "~7" } }
I know that in a Linux Function App you can set the the Python version using:
site_config { linux_fx_version = "PYTHON|3.9" }
Is there any update on this issue?
I'm seeing the same issue with powershell Core Version.
app_settings = { FUNCTIONS_WORKER_RUNTIME = "powershell" FUNCTIONS_WORKER_RUNTIME_VERSION = "~7"
}
Does not work for me.
Terraform v0.15.4 on darwin_amd64
- provider registry.terraform.io/hashicorp/azurerm v2.60.0
Any work arounds?
Here is my workaround in an Azure DevOps pipeline PowerShell step:
# Change function app to PS 7
Write-Host '##[group]Change function app to PS 7'
$function = az functionapp show --name $functionappname --resource-group $rgname | ConvertFrom-Json
if($function.siteConfig.powerShellVersion -ne "~7") {
Write-Host "Updating powershell version to ~7..."
az functionapp update --name $functionappname --resource-group $rgname --set "siteConfig.powerShellVersion=~7"
} else {
Write-Host "Powershell version already set to to ~7"
}
Write-Host '##[endgroup]'
Edit:
The powerShellVersion was previsously not returned from Azure CLI at all, but it was still setable. Now it is indeed returned, so maybe that Go SDK also returns this value and makes it possible to set?
I am also facing the same issue !! Any Update on when this will be fixed?
same issue here, would like any update on this :-)
Heya, just to build on the great work by @mariussm and as an alt take.
I did this as a work around and it worked okay running in ADO pipeline but would work anywhere the cli is installed I think I'm pretty novice at Terraform so there's likely much more robust ways of doing this.
resource "null_resource" "ucf_fa" {
provisioner "local-exec" {
command = <<-EOT
az login --service-principal --username '${var.sp_appid}' -p='${var.sp_appsecret}' --tenant "${var.tenant}"
az functionapp update --name ${azurerm_function_app.ucf_fa.name} --resource-group ${azurerm_function_app.ucf_fa.resource_group_name} --set siteConfig.powerShellVersion=~7
EOT
}
depends_on = [azurerm_function_app.ucf_fa]
triggers = {
build_number = "1"
}
}
@gabrielmccoll, Yes .. thank you so much. I am also very new to terraform.
- In my 1st approach i was executing the az cli commands from the pipeline to set the PowerShellVersion.
- Then one of my colleagues recommended that in Terraform we should use a null resource to achieve this, exactly 💯 like you have shown.
Thank you so much ! This workaround is good for me now 😌
PowerShell 6 Support is ending September 30, 2022... would be great to have this feature added!
https://azure.microsoft.com/en-us/updates/azure-functions-support-for-powershell-6-is-ending-on-30-september-2022/
I'm also running into this issue. Hard to advocate for IaC when there's a need for manual changes via console.
Update: Found the Azure Functions Core Tool. It can initialize the function locally with the required app files. In this scenario, I initialized my function in PowerShell and published it to the function app. Here's a video that I followed.
Working on a tf local-exec
resource that will create the directory and initialize the function. After that, I'll need to update my azure cli docker image to include the azure functions tool, and change the CI to publish the function if changes in the function's directory have occurred.
I'm also getting this issue. Have to update it manual in Azure Portal. It would be nice if this can be done by terraform script
+1 also having the same issue. Feels like this should have been updated some time ago as it's quite common config for functions.
I found the workaround: siteConfig.powerShellVersion=~7
doesn't work for me.
I got that this works
site_config {
linux_fx_version = "PowerShell|7"
}
I found the workaround:
siteConfig.powerShellVersion=~7
doesn't work for me.I got that this works
site_config { linux_fx_version = "PowerShell|7" }
This only works with Linux App Service Plans and Linux Function Apps. A solution is still needed for Windows-based apps and plans.
Hi Team,
Do you have any update on that issue?
This is supported through the powershell_core_version application_stack
element, you have to move to azurerm_windows_function_app
first.
This is supported through the powershell_core_version
application_stack
element, you have to move toazurerm_windows_function_app
first.
Hello.
Terraform version : 0.14.1 AzureRM version : 3.17.0
Still Ko PowerShell 7 & 7.2 with azurerm_windows_function_app
, applying a second time does not solve the problem
Configuration => General settings :
Template ARM :
However, stack PowerShell 7 & 7.2 work well with azurerm_linux_function_app
If anyone has a solution to the problem, I'm interested. Thanks
Same issue, both on azurerm_windows_function_app & the former azurerm_function_app.
I was able to do it successfully by putting the application_stack
block inside of the site_config
block, for example:
site_config {
use_32_bit_worker = false
ftps_state = "FtpsOnly"
application_stack {
powershell_core_version = 7.2
}
}
After applying the above terraform plan, I confirmed it was in fact using 7.2 by running the following azcli command: az functionapp config show --name myFunctionAppName --resource-group myResourceGroupName
and the output showed the following result:
"windowsFxVersion": "PowerShell|7.2",
I re-confirmed by changing the version in the terraform config to 7
, reran the command to show the configuration, and the output shown as:
"windowsFxVersion": "PowerShell|7",
So it appears to be functioning correctly, even though the PowerShell Core Version
in the general app settings web page is blank.
References: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_function_app#application_stack
@tjgruber did you confirm that your function app is actually working by calling a function inside your function app?
@erwinkramer I tested a simple PowerShell HTTP Trigger, and it was successful. I also tested creating a Durable Function, and it let me.
I think Microsoft made Powershell 7 default so it would work now no matter what, maybe confirm the Powershell version inside the function by calling $PSVersionTable.PSVersion? Then we know for sure sure it's actually using 7.2 and not falling back to 7
The function itself is actually defaulting to 7.0.12
.
I just did a comparison, of before and after setting it manually in the Web GUI. Everything stays the same, except these changes:
So I did yet some more digging through the Terraform documentation and Microsoft App Settings documentation, found the powerShellVersion
supported there all the way at the bottom, and added those recommended changes to the Terraform config, which it accepts:
app_settings = {
"powerShellVersion" = "~7",
}
site_config {
remote_debugging_version = "VS2019"
application_stack {
powershell_core_version = 7.2
}
}
I used Microsoft's suggested "~7"
, along with all other combinations, none of which work. When I output the settings config, it always shows blank "powerShellVersion": "",
. The only way I've seen to change it so far is manually in the Web GUI.
The Terraform config doesn't accept "powerShellVersion" = "~7"
anywhere else, as it's an app setting.
I also tried without the application_stack
and using the following app_settings, with no luck:
app_settings = {
"FUNCTIONS_WORKER_RUNTIME" = "powershell",
"FUNCTIONS_WORKER_RUNTIME_VERSION" = "~7",
}
app_settings = {
"WEBSITE_RUN_FROM_PACKAGE" = "",
"netFrameworkVersion" = "v6.0",
"FUNCTIONS_WORKER_RUNTIME" = "node",
"powerShellVersion" = "~7",
"FUNCTIONS_WORKER_RUNTIME_VERSION" = "~7",
}
...and different combinations, not exactly what's above, but including what's there.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings#powershellversion
https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings#netframeworkversion
etc... I tried all kinds of combinations from the documentation, and it's not clear anywhere how to specify this in Terraform using the Terraform resource azurerm_windows_function_app
.
The way the Terraform resource is interacting with the Azure API or however it's doing it, seems to need fixed. If there is a way to set the PowerShell Core Version in the Terraform config, it's certainly not clear.
I'm going to continue to try to get this working through Terraform config, because I don't want to have to manually set things through Azure Web GUI, that defeats the whole purpose of Terraform. I'll come back here if I figure it out. Otherwise, hopefully someone from Terraform can comment on this.
In addition to the above, I haven't even been successful in changing the PowerShell version from 7 to 7.2 via Azure CLI. It may be a limitation in Azure CLI, therefore the azurerm_windows_function_app resource. It does look possible to upgrade from 7 to 7.2 via Azure PowerShell and ARM templates... but I'd really like to do this with Terraform.
Hello. Since azurerm v3.39.0, the problem does not seem to be present anymore. this issue can be closed.
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.