How to specify .net core version with Terraform azurerm_app_service How to specify .net core version with Terraform azurerm_app_service azure azure

How to specify .net core version with Terraform azurerm_app_service


You need to specify the following 2 settings in site_config block of the app_service block. for e.g.

resource "azurerm_app_service" "app_service" {  name                = local.graphql_server_long_name  location            = var.azure_region  resource_group_name = azurerm_resource_group.rg.name  app_service_plan_id = azurerm_app_service_plan.graphql_server.id  site_config {    linux_fx_version = "DOTNETCORE|5.0"    dotnet_framework_version = "v5.0"  }

which are linux_fx_version and dotnet_framework_version.

You need to be running atleast 2.38.0 version of azurerm provider. You can check this by running terraform version in the directory which contains your tf files and it will display the terraform cli and all used providers version


You could try to query the available runtimes of the AppService/WebApp with the Azure CLI.

https://docs.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az-webapp-list-runtimes

Alternatively

You could configure your app service to use a container of your app with .NET Core. This will allow you to specify the .NET Core version through the Dockerfile. The downside is you will need some sort of registry (Azure Container Registry).


There are 2 available options to host .NET core application in App Service:

  1. Windows App Service plan.
  2. Linux App Service plan (default option, when you created App Service on Azure portal).

If you are using Windows App service plan, you need to specify dotnet_framework_version and as you mentioned, there is only 2 available options - v2.0 and v4.0.

Instead, you can use the Linux App Service plan and specify the .net version inlinux_fx_version field (dotnet_framework_version should be empty).
Some sort of this:

resource "azurerm_app_service" "stackoverlow_service" {  name = "stackoverlow-test-net-version"  location = "centralus"  resource_group_name = "{resource_group_name}"  app_service_plan_id = "{app_service_plan_id}"  site_config {    linux_fx_version = "DOTNETCORE|2.2"    min_tls_version = "1.2"    always_on = true    scm_type = "None"    managed_pipeline_mode = "Integrated"    websockets_enabled = false    use_32_bit_worker_process = true  }}

App Service is a pretty complex product with many configuration options and Azure/terraform documentation does not cover well all aspects.
To generate desired configuration, you can create App Service in Azure and import resource to terraform:

  1. create minimal correct App Service resource in terraform.
  2. create App Service with desired config in Azure portal.
  3. import resource using terraform import command :terraform import azurerm_app_service.stackoverlow_service /subscriptions/.....
  4. run terraform plan to see the exact difference or check the terraform state file.