terraform-provider-azurerm: azurerm_windows_function_app dotnet version not set correctly

Is there an existing issue for this?

  • I have searched the existing issues

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

Terraform Version

1.1.8

AzureRM Provider Version

3.2.0

Affected Resource(s)/Data Source(s)

azurerm_windows_function_app

Terraform Configuration Files

resource "azurerm_windows_function_app" "fun-app" {
  name                        = "${local.name_slug}functionapp"
  location                    = azurerm_resource_group.rg.location
  resource_group_name         = azurerm_resource_group.rg.name
  service_plan_id             = data.azurerm_service_plan.asp.id
  storage_account_name        = azurerm_storage_account.sa.name
  storage_account_access_key  = azurerm_storage_account.sa.primary_access_key
  functions_extension_version = "~4"
  site_config {
    always_on = true
    scm_use_main_ip_restriction = "false"
    worker_count = 2
  
    application_stack {
      dotnet_version = "6"
    }
}
}

Debug Output/Panic Output

Deploys without issue

Expected Behaviour

The expected behavior is to deploy a windows function app with function runtime ~4.

Actual Behaviour

The actual result of deployment is runtime version “custom” and the only supported drop down is ~3. I’m assuming the reason for “custom” is the function app was created with dotnet version 3.1 and does not support runtime ~4 only ~3, however I specified dotnet 6 in TF. When I create manually in azure portal the function app is created with the correct dotnet 6. I can even import the manually created function app to the same resource in terraform state with no issues.

Steps to Reproduce

Just try to create a function app using the new azurerm_windows_function_app with dotnet 6 and runtime ~4.

I’m assuming the configuration for dotnet 6 is under application stack and runtime version is under functions_extension_version.

functions_extension_version = “~4” application_stack { dotnet_version = “6”

I tried both options 3.1 and 6 (as documented) both yield the same result.

Important Factoids

no

References

no

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 42
  • Comments: 24 (4 by maintainers)

Most upvoted comments

Likewise, I have the same issue.

PS C:\Users\ryan.stanley\Downloads\Function> terraform version
Terraform v1.1.9
on windows_amd64
+ provider registry.terraform.io/aztfmod/azurecaf v2.0.0-preview-2
+ provider registry.terraform.io/hashicorp/azurerm v3.3.0
+ provider registry.terraform.io/hashicorp/local v2.2.2

Upon further investigation, I have found in the azure resource browser: https://resources.azure.com/

The configuration config document has the following values when created using the azurerm_windows_function_app terraform resource:

        "netFrameworkVersion": "v4.0",
        "phpVersion": "",
        "pythonVersion": "",
        "nodeVersion": "",
        "powerShellVersion": "",
        "linuxFxVersion": "",
        "windowsFxVersion": "DotNet|6",

Upon creating the resource manually via the azure ui/portal:

        "netFrameworkVersion": "v6.0",
        "phpVersion": "",
        "pythonVersion": "",
        "nodeVersion": "",
        "powerShellVersion": "",
        "linuxFxVersion": "",
        "windowsFxVersion": null,

NOTE: the netFrameworkVersion and windowsFxVersion are different. I think that the later should be the correct values for this not the ones that are being created at present.

Upon manually updating the attributes via the eddittor the ~4 function version was available in the drop down.

UPDATE: Further to this my workaround has been to run:

az functionapp config set --net-framework-version v6.0 -n $Function -g $resourceGroup

This setep is run within my automation during the software deployment phase as I use PowerShell to deploy the functions contents, therefore, this is the most logical I’m my instance.

I’m using AzAPI provider to resolve any of these types of issues.

New deploy reference:

Update existing example:

resource "azurerm_windows_function_app" "demoapp" {
  provider = azurerm.corpventure0002
  name                = "demoapp"
  resource_group_name = azurerm_resource_group.rg-function-app.name
  location            = var.region
  service_plan_id = azurerm_service_plan.appsp-ep.id
  storage_account_name = azurerm_storage_account.sa.name
  storage_account_access_key = azurerm_storage_account.sa.primary_access_key
  https_only = true
  virtual_network_subnet_id   = azurerm_subnet.appservice-vnet-integration-01.id
  site_config {
      pre_warmed_instance_count = 2
      vnet_route_all_enabled    = true
  }
  app_settings = {
    WEBSITE_CONTENTOVERVNET   = 1
    WEBSITE_CONTENTSHARE = azurerm_storage_share.sashare.name
    WEBSITE_CONTENTAZUREFILECONNECTIONSTRING = azurerm_storage_account.sa.primary_connection_string
    FUNCTIONS_WORKER_RUNTIME = "dotnet"
    FUNCTIONS_EXTENSION_VERSION = "~4"
  }
}

resource "azapi_update_resource" "this" {
  type = "Microsoft.Web/sites/config@2022-03-01"
  name = "web"
  #resource_id = azurerm_windows_function_app.fa-test-vnet-content2.id
  parent_id = azurerm_windows_function_app.demoapp.id
  body = jsonencode({
    properties = {
      netFrameworkVersion = "v6.0"
    }
  })
}

There are numerous issues with this resource type over the old one - it also won’t generate host keys either. https://github.com/hashicorp/terraform-provider-azurerm/issues/17750

I’ve switched back to the old resource azurerm_function_app - these new ones just don’t work. The fact that this issue was raised in April and its now nearly August proves my point. I’ve no idea why these where introduced in this state.

Guide/info here also.

Thanks guys for raising the issue. For the newly created windows functions, we will set the .NetFrameworkVersion to v6.0 if dotnet_version sets to 6 in the TF config, it should fix the issue custom ~4. As mentioned in our docs, function runtime 4.0 requires the underlying .Net version6, if the functions are created before, please aslo set the .net version to 6 when upgrading the function worker runtime to 4 and it should resolve custom ~4 situation.

I am experiencing the same problem with the azurerm_linux_function_app. Any updates on the triage?