azure-functions-host: Application settings not available from local.settings.json in Azure, but available locally in Visual Studio

My appsettings from local.settings.json were not available in Azure.

My settings were put in local.settings.json. I only put the settings I wanted to override in the Azure Portal since I want to have the common settings in version control.

It turned out that the settings from the Azure Portal were available, but the ones that were not overridden (that should be loaded from local.settings.json) were not available.

Expected behavior

I expect Azure to read the settings from local.settings.json first, and then override them with values defined in the portal.

Actual behavior

In the remote Azure environment the local.settings.json settings were not available (ConfigurationManager.AppSettings["FromAddress"] returned null for a setting called FromAddress defined in the Values section of the json file.

They are available locally in Visual Studio.

Known workarounds

Define all the settings in the Azure portal, even the ones that are the same for local development and Azure

Related information

  • I use VS 2017 15.3 Preview 2.0 with Functions Tools for VS 2017
  • I develop a precompiled C# Azure Function

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 27 (5 by maintainers)

Most upvoted comments

I agree that we shouldn’t be checking in secrets, but local.settings.config isn’t just secrets. Some settings are added just to avoid hard-coded values in code. By adding local.settings.json to .gitignore (or just choosing not to check it in), we make it difficult for the next developer to pick it up and start debugging locally. They either have to recreate the JSON file, have it emailed from a previous developer or otherwise manage these files. This was a problem recently when our code was handed off to the support team; when they needed to make their first change, nothing would run because they had no local.settings.file.

This problem doesn’t exist in CI/CD, but CI/CD isn’t used to set up a dev environment.

Regarding not having a web.config equivalent for function projects … this is a very big pain … we have streamlined our delivery pipeline for web apps on different environments using configuration files and config transforms … and now we should move to arm templates parameters file to get the same result when using Azure Functions projects instead of azure web app projects …

I hope that soon azure functions can read settings from a json file (ok xml is no more sexy enough) and that something like this https://github.com/Microsoft/json-document-transforms/wiki for json transform will be supported in vsnet

enrico

I wouldn’t expect LOCAL settings to be available in Azure. 😃

Your workaround is actually the expected behaviour - please someone correct me if I’m wrong.

Our Octopus server handles the transforms of secrets and connection strings so they are not in source control. The behavior differs from how other Microsoft products do it, and that is a pain.

@bgoldman69 I’m not sure what you mean, can you elaborate? My CI/CD setups use ARM templates to deploy the function apps with the appropriate app settings. These ARM templates are in source control and have CD hooked up so when I need to add a new app setting I just commit the changes to the ARM template.

so basically this means that integrating azure functions into existing CI/CD pipelines is a show stopper for most MS centric shops.

I wouldn’t expect to deploy the ARM template when deploying a specific application that that is hosted in the resource group. I look at the ARM template as the configuration for the resources in a resource group, not application specific information that the resources contain. Each time I deploy a web app, I don’t deploy the ARM template only the web app (unless there is a change to the resource group itself, which would be a separate package and deployment). I treat these as totally separate things and separate repos.

@thusnjak have you seen https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#publish ? I haven’t tested but seems to publish the settings.

I have been updating the portal app settings using an arm template.

You can deploy an ARM template from your powershell using New-AzureRmResourceGroupDeployment like this:

$ResourceGroupName = "MyResourceGroupWhichWillContainTheAzureFunction"
New-AzureRmResourceGroupDeployment -Mode Incremental  -TemplateFile azureFunctionTemplate.json -ResourceGroupName $ResourceGroupName -fnName "functionName" -username "myUsername" -password "some secret"

Another option is to use the -TemplateParameterFile and have all the parameter values in a json file.

All parameters will be picked up by the ARM Template and you can set the appSettings section of the ARM template like the following:

{
  "$schema": "http://schemas.management.azure.com/schemas/2015-01-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "fnName": {
      "type": "string"
    },
    "username": {
      "type": "string"
    },
    "password": {
      "type": "string"
    }
  },
  "variables": {
    "functionAppName": "[parameters('fnName')]",
    "hostingPlanName": "I can hardcode staff here",
    "location": "[resourceGroup().location]"
  },
  "resources": [
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2015-04-01",
      "name": "[variables('hostingPlanName')]",
      "location":  "[variables('location')]",
      "properties": {
        "name": "[variables('hostingPlanName')]",
        "computeMode": "Dynamic",
        "sku": "Dynamic"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('functionAppName')]",
      "location": "[variables('location')]",
      "kind": "functionapp",
      "properties": {
        "name": "[variables('functionAppName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
      ],
      "resources": [
        {
          "apiVersion": "2016-03-01",
          "name": "appsettings",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', variables('functionAppName'))]"
          ],
          "properties": {
            "FUNCTIONS_EXTENSION_VERSION": "latest",
            "WEBSITE_CONTENTSHARE": "[toLower(variables('functionAppName'))]",
            "WEBSITE_NODE_DEFAULT_VERSION": "6.5.0",
            "BackendUsername": "[parameters('username')]",
            "BackendPassword": "[parameters('password')]"
          }
        }
      ]
    }
  ]
}

What is the process by which the local.settings.json settings should be published to Azure Portal from VS? Currently the VS publish process ignores these settings.

It is just confusing as for other App Services types it IS normal to have a file with settings (app.config / web.config) that contains the default values, which can be overridden in the Azure Portal. Also, the local.settings.json file is deployed to Azure. I expect it to read it.