I have created an Azure Web App using terraform but it has the wrong version of NodeJS in it.
resource "azurerm_app_service_plan" "app-plan" {
name = "${var.prefix}-app-plan"
resource_group_name = var.resource_group_name
location = var.resource_group_location
sku {
tier = "Free"
size = "F1"
}
}
#azurerm_app_service doesn't support creating Node.JS 8.10 apps
#https://github.com/terraform-providers/terraform-provider-azurerm/issues/4144
resource "azurerm_app_service" "app-service" {
name = "${var.prefix}-app"
resource_group_name = var.resource_group_name
location = var.resource_group_location
app_service_plan_id = azurerm_app_service_plan.app-plan.id
}
I have tried updating the configuration using the rest api
{
"properties": {
"nodeVersion": "8.10"
}
}
and also updating the application settings using the rest api
{
"properties": {
"WEBSITE_NODE_DEFAULT_VERSION": "8.10"
}
}
However, when I run the Console it still says node --version v0.10.40
When I run env it looks like the PATH variable is incorrect.
Node 8.10 does exist on the machine at D:\Program Files (x86)\nodejs\8.10.0
How can I update the path from the rest api?
Are there any alternatives?
My preferences are terraform > az cl > rest api
Note:
Bear in mind that when I create the web app in the portal, selecting Node 8.10 forces me to choose Windows as the O/S.
Under site_config, linux_fx_version should be set to "NODE|8.10"
I have gotten it to work with node 10.14, using:
site_config {
linux_fx_version = "NODE|10.14"
}
You can also see different examples of azure web apps over at:
https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/app-service
In the portal it specifies Node 8.10 as a Runtime stack.
The az cli specifies 8.10 as a runtime:
az webapp list-runtimes|grep "8.10"
"node|8.10",
However, as you can see in the question, the version installed is 8.10.0.
If we set this in the application settings with terraform this (unintuitively) sets the correct node version:
resource "azurerm_app_service" "app-service" {
name = "${var.prefix}-app"
resource_group_name = var.resource_group_name
location = var.resource_group_location
app_service_plan_id = azurerm_app_service_plan.app-plan.id
app_settings = {
#The portal and az cli list "8.10" as the supported version.
#"8.10" doesn't work here!
#"8.10.0" is the version installed in D:\Program Files (x86)\nodejs
"WEBSITE_NODE_DEFAULT_VERSION" = "8.10.0"
}
}
Related
I have little problem that I am trying to solve.
I am trying to create function apps using terraform as IaC and my only problem is with functions extension version in version 4.
When I insert the variable like this:
functions_extension_version = "~4"
I get this version as custom (I am trying to create Dotnet version 6 so it must be version 4)
But when I use version 3 like this:
functions_extension_version = "~3"
it works fine
I know my app service plan is support functions extension version 4 becuase when I try to create manually it is working as expected.
Thanks
edit:
full TF code:
resource "azurerm_windows_function_app" "function_windows" {
# condition
count = var.to_create ? 1 : 0
# basic info configuration
name = var.name
resource_group_name = var.resource_group_name
location = var.location
storage_account_name = data.azurerm_storage_account.storage_account.name
storage_account_access_key = data.azurerm_storage_account.storage_account.primary_access_key
service_plan_id = var.app_service_plan_id
# function configuration
https_only = true
functions_extension_version = "~4"
site_config {
application_stack {
dotnet_version = var.runtime == "dotnet" ? var.runtime_version : null
java_version = var.runtime == "java" ? var.runtime_version : null
node_version = var.runtime == "node" ? var.runtime_version : null
}
scm_use_main_ip_restriction = true
elastic_instance_minimum = local.elastic_instance_minimum
}
identity {
type = "SystemAssigned"
}
tags = var.tags
}
Your app is pinned to an unsupported runtime version for ‘dotnet’. For better performance, we recommend using one of our supported versions instead: ~3.
There are no issues with your terraform code, but the issue I found is with the version running in the backend.
According to #Sandro Pereira's blog,
If you encounter this kind of error or a similar alert, it signifies that the runtime version you defined uses an unsupported version of .NET Framework. In some instances, although your
function runtime version = ~4 works with .NET framework v6.0, but it actually runs using v4.0 in the backend.
Runtime version ~3 normally runs on top of .NET Framework v4.0. However, runtime version ~4 requires .NET Framework v6.0.
By referring terraform registry, I created the replica of a function app with terraform and deployed successfully.
Code snippet:
resource "azurerm_function_app" "newfunc" {
name = "test-azure-functions"
location = azurerm_resource_group.newfunc.location
resource_group_name = azurerm_resource_group.newfunc.name
app_service_plan_id = azurerm_app_service_plan.newfunc.id
storage_account_name = "mystorage"
}
After successful deployment in Azure portal:
You can validate which version of .NET is running for your function app by checking:
Resource Explorer (azure.com)
Validate the netFrameworkVersion:
Note: Refer the above blog for path to validation
In our Application Insights logs for Azure Functions there are a lot of warnings with the message:
The Dashboard setting is no longer supported. See https://aka.ms/functions-dashboard for details.
We build our Azure resources using Terraform, and since our Function Apps target the "~4" runtime version we don't add the AzureWebJobsDashboard setting to our Function's Application settings. (According to the docs: The AzureWebJobsDashboard setting is only valid for apps that target version 1.x of the Azure Functions runtime.)
I was therefore surprised to find the AzureWebJobsDashboard setting with a value in the Azure portal. Any idea how it got there?
I deleted the setting manually in the portal for four of the apps we have running, and the logged warnings went away - however, the setting reappeared in one of them after a little while 🤯 Is there any way to make sure the deletion is permanent?
Edit: I tried deleting the setting manually for four new apps - making sure to save the changes, and the setting reappeared in two of them after some hours.
Edit2: After 1-2 days the setting is back in all eight apps.
There's a special setting builtin_logging_enabled in terraform resource for Azure functions:
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app#enable_builtin_logging
Setting it to false should disable AzureWebJobsDashboard.
Just add it in your azurerm_windows_function_app resource like this:
resource "azurerm_windows_function_app" "func" {
name = "sample-function-app"
builtin_logging_enabled = false
...
}
We have tried the same in our environment to check ,when deploying azure function using terraform if AzureWebJobsDashboard is there or not.
Yes, It was there and the document you followed which is correct , So to it manually we need to follow the below to resolve the above issue.
To do that make sure that we have applied the APPINSIGHTS_INSTRUMENTATIONKEY after deleting AzureWebJobsDashboard
And enabled App insights for our function app as shown below and the value will be store automatically after enable.
In your case, the configuration is appeared automatically after sometime or days, But if we enabled the aforementioned it seems to be work. As we checked several times but still its not appeared.
NOTE:- we used Python3.9 with function runtime v4 in Linux environment.
Below is the terraform code that we used for reproducing;
main.tf
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "ajayXXXX"
location = "West Europe"
}
resource "azurerm_storage_account" "example" {
name = "exatst"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_service_plan" "example" {
name = "example-service-plan1"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
os_type = "Linux"
sku_name = "S1"
}
resource "azurerm_linux_function_app" "example" {
name = "funterraform"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
service_plan_id = azurerm_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
site_config {
application_stack {
python_version = "3.9"
}
}
}
resource "azurerm_function_app_function" "example" {
name = "example-function-app-function"
function_app_id = azurerm_linux_function_app.example.id
language = "Python"
test_data = jsonencode({
"name" = "Azure"
})
config_json = jsonencode({
"bindings" = [
{
"authLevel" = "function"
"direction" = "in"
"methods" = [
"get",
"post",
]
"name" = "req"
"type" = "httpTrigger"
},
{
"direction" = "out"
"name" = "$return"
"type" = "http"
},
]
})
}
Source Code taken from : HashiCrop Terraformregistry|azurerm_function_app_function
For more information please refer the below links:-
GitHub Issue| Remove support for AzureWebJobsDashboard
MICROSOFT DOCUMENT| App settings reference for Azure Functions.
I would like to add a new API version under the existing API that is already there. I can do that easily via the Portal UI however, can someone please guide me to how to achieve this via Terraform? Any sample snippet would be helpful.
I am trying to reverse engineer v1, v2 of this into Terraform. Thanks.
Terraform supports API Version Set and reference it in the API:
version - (Optional) The Version number of this API, if this API is versioned.
version_set_id - (Optional) The ID of the Version Set which this API is associated with.
NOTE:
When version is set, version_set_id must also be specified
resource "azurerm_api_management_api_version_set" "example" {
name = "example-apimapi"
resource_group_name = var.resource_group_name
api_management_name = var.apim_name
display_name = "ExampleAPIVersionSet"
versioning_scheme = "Segment"
}
resource "azurerm_api_management_api" "example" {
name = "example-api"
resource_group_name = var.resource_group_name
api_management_name = var.apim_name
revision = "1"
display_name = "Example API"
path = "example_me"
protocols = ["https"]
service_url = "https://conferenceapi.azurewebsites.net/"
version = "v1"
version_set_id = azurerm_api_management_api_version_set.example.id
import {
content_format = "swagger-link-json"
content_value = "http://conferenceapi.azurewebsites.net/?format=json"
}
}
There's a tutorial for doing it the Portal: Tutorial: Publish multiple versions of your API
When you create multiple versions, the Azure portal creates a version set, which represents a set of versions for a single logical API. Select the name of an API that has multiple versions. The Azure portal displays its Version set. You can customize the Name and Description of a virtual set.
While updating an Azure App Service App Setting with Terraform we're getting the following error:
{"Message":"AppSetting with name 'HEALTHCHECKS-UI_HEALTHCHECKS_0_NAME' is not allowed."}
However if we add it via the portal manual it works totally fine:
I'm guessing it's something to do with the 0 or - but how do we escape these?
The Terraform code is pretty simple but here is a failing example:
resource "azurerm_resource_group" "test" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_app_service_plan" "test" {
name = "example-appserviceplan"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "example-app-service"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
site_config {
dotnet_framework_version = "v4.0"
scm_type = "LocalGit"
}
app_settings = {
"HEALTHCHECKSUI_HEALTHCHECKS_0_NAME" = "Self"
"HEALTHCHECKSUI_HEALTHCHECKS_0_URI" = "https://${var.environment_name}-example-app-service/health-api"
}
}
Dropping into the bash terminal in kudo and running printenv shows that setting it manually removes the -:
HEALTHCHECKSUI_HEALTHCHECKS_0_NAME=https://example-app-service.azurewebsites.net/health-api
Not sure, I do not find the document to show the limitation of this for the app settings in Azure App Service. But as I know, the operating system has the limitation of this. For Linux, you cannot set the environment variable with the name contains -. But in Windows, the limitations for - does not exist. Generally, letters and numbers are no problem in both systems.
Remove - (Dash) from environment variables names. It will work fine
Ex: Test-Pass --> TestPass
I have an example how to deploy azure function using terraform. But, unfortunately, it deploys only zip package. Is there are any other way to do it? How can I deploy multiple packages into one function? How can I configure proxy using terraform?
resource "azurerm_function_app" "azure_function_scenario1_hop2" {
name = "scenario1-hop2-azure-function"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
app_service_plan_id = "${var.app_service_plan_id}"
storage_connection_string = "${var.storage_connection_string}"
app_settings {
APPINSIGHTS_INSTRUMENTATIONKEY = "${var.instrumentation_key}"
HASH = "${base64sha256(file("./../bin/scenario1_hop2_node.zip"))}"
WEBSITE_USE_ZIP = "https://github.com/lmolotii/azure-functions-playgroud/raw/master/scenario1_hop2_node.zip"
}
}
As of version 3.0 of the azurerm provider, you can deploy Functions using Terraform. You just need the azurerm_function_app_function resource as is documented here: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app_function