site_config configuration in azure terraform

Viewed 68

For examples I've seen of a .NET application deployment to azure, people mention the site_config parameter, however this doesn't seem to be well explained in the official docs , only that it's optional. So, I just guessed, seeing the azure interface that this probably is the runtime environment maybe?: enter image description here

The examples I've mostly found contain something like this:

resource "azurerm_app_service" "appService" {
  app_service_plan_id = azurerm_app_service_plan.appPlan.id
  location = azurerm_resource_group.rg.location
  name = "nestjs"
  resource_group_name = azurerm_resource_group.rg.name

  site_config {
    dotnet_framework_version = "v4.0"
    remote_debugging_enabled = true
  }
}  

I didn't find much on nodejs except for this thread, but, azure doesn't have these versions, so a bit confused: enter image description here

What is the site_config exactly? Is it specifying the Run Time Environment that our apps going to be using? If yes, then why is it optional? If not, then how is the RTE specified?

1 Answers

You can check the available node versions first to set .

az webapp list-runtimes

enter image description here

  • azurerm_app_service resource has been deprecated in version 3.0 . Please use resource "azurerm_windows_web_app" in case of windows OS and azurerm_linux_web_app in case of linux.
  • remote_debugging_version , application_stack are among the arguments that are supported by site_config block wherein application_stack has this current_stack option where we can set the runtime version or application stack settings.
  • site_config block supports the following optional arguments in which always_on ,api_management_api_id ,app_command_line ,application_stack ,…,cors http2_enabled ,ip_restriction ,remote_debugging_version and so on application_stack

I tried in my environment where application_stack has current_stack which is Application Stack for the Windows Web App. Possible values are dotnet, dotnetcore, node, python, php, and java.

NOTE from:windows_web_app application_stack #current_stack

Whilst this property is Optional omitting it can cause unexpected behaviour, in particular for display of settings in the Azure Portal.

when current_stack is set to node, node_version can be used to set its version and can be 14-lts, and 16-lts(which are available )

NOTE: from linux_web_app#node_version : 10.x versions are deprecated and may not work for new resources.

provider "azurerm" {

  features {

resource_group {
  prevent_deletion_if_contains_resources = false
  }

}
}


resource "azurerm_resource_group" "example" {
  name     = "myrg"  
 location = "westus2"
}



resource "azurerm_service_plan" "example" {
  name                = "kaexampleplan"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku_name            = "P1v2"
  os_type             = "Windows"
}

resource "azurerm_windows_web_app" "example" {
  name                = "kaexamplewebapp"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_service_plan.example.location
  service_plan_id     = azurerm_service_plan.example.id
  

  site_config {
    always_on                 = true
    application_stack {
      current_stack  = "node"
      #node_version = "16-LTS"
      
    }

  }

  app_settings = {
    WEBSITE_NODE_DEFAULT_VERSION ="16-LTS"
  }
}

I tried to create 'WEBSITE_NODE_DEFAULT_VERSION' through app settings , as the node version can be seen in that parameter when even created app service using the portal.

enter image description here

App service created with Windows OS

enter image description here

enter image description here

  • Then you can check the version using this cli command:

az webapp config appsettings list --name <webappname>--resource-group v-sakavya-Mindtree --query "[?name=='WEBSITE_NODE_DEFAULT_VERSION'].value"

  • Or to set supported Node.js version in cloudeshell to set WEBSITE_NODE_DEFAULT_VERSION

    az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_NODE_DEFAULT_VERSION="~16"

Reference :azurerm_windows_web_app - current_stack · Issue #16222 · hashicorp/terraform-provider-azurerm · GitHub

Related