14

Out of the box, I think azurerm_app_service provider does allow us to specify the .Net framework version, by utilising the dotnet_framework_version field.

dotnet_framework_version - (Optional) The version of the .net framework's CLR used in this App Service. Possible values are v2.0 (which will use the latest version of the .net framework for the .net CLR v2 - currently .net 3.5) and v4.0 (which corresponds to the latest version of the .net CLR v4 - which at the time of writing is .net 4.7.1). For more information on which .net CLR version to use based on the .net framework you're targeting - please see this table. Defaults to v4.0.

https://www.terraform.io/docs/providers/azurerm/r/app_service.html#dotnet_framework_version

The document says that the possible values are v2.0 or v4.0.

But what if I am targeting .NET Core, say v2.2 instead? What am I supposed to do here?

Azure portal allows selecting .NET Core from the drop down menu. (see screenshot below)

enter image description here

I am not sure whether or not there's a way to do this with Terraform azurerm_app_service as well.

Marko E
  • 13,362
  • 2
  • 19
  • 28
woodykiddy
  • 6,074
  • 16
  • 59
  • 100
  • If it works like IIS, then I think it you don't need (and want) to specify this property because it will not use it. I think when you don't specify it, it will act like "No Managed Code" in IIS. They should add extra info to this property in the documentation. And the just pick .NET Core 2.2 in the Runtime Stack box. See #6 on https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index?view=aspnetcore-2.2#create-the-iis-site – KoalaBear Jun 13 '19 at 05:13
  • 4
    I don't think you need to worry about this. By default, I believe those app service instances will always have .NET Core installed anyway, so it depends on your app which version it will use. – Knelis Jun 13 '19 at 07:04
  • 3
    How did you solved this? – tomab Aug 23 '19 at 07:08
  • I disagree with the comment "I don't think you need to worry about this." Seeing Stack = ".NET" and .NET Framework version = "V4.*" gives an inaccurate impression of the run-time environment when looking at General Settings in the dashboard. I too want to specify this in my Terraform script. – Michael Feb 04 '20 at 18:24

3 Answers3

1

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.
Dmytro Kutetskyi
  • 701
  • 6
  • 11
0

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

https://learn.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).

Fabian B
  • 31
  • 3
0

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"
  }

those are linux_fx_version and dotnet_framework_version.

You need to be running at least 2.38.0 version of azurerm provider. You can check this by running the following command in the directory which contains your terraform files: terraform version

This will display the terraform cli and all used providers.

Noah
  • 188
  • 4
  • 24
adeel41
  • 3,123
  • 1
  • 29
  • 25