3
votes

I have about 20+(and growing) app settings in local.settings.json file of my .net core azure function app. The only way to add these to function app in the portal as part of the deployment is to use a long concatenated string of all appsettings in key value format which is very messy, error prone and hard to maintain.

I am looking for a neat way if possible to add the appsettings to the function app as part of the function app deployment process.

P.S. I am using terraform to create the function app and Not interested to use the ARM template solution which is even messier.

2
Control your app settings via Terraform. Run Terraform as part of your deployment pipeline.Daniel Mann
Thanks @DanielMann. Currently i have only added infra specific app settings in terraform config for function app. i.e) the connection string, appinsightskey, dotnetversion etc. and these gets deployed as part of the infrastructure pipeline which creates all resources. I was thinking to add the app specific settings as part of the code deployment pipeline. do you know of any way to do that as part of the app service deployment task? or terraform is the best available optionsajid

2 Answers

2
votes

If you want to add the appsettings to the function app as part of the function app deployment task. You can use variables to make it a little easier to maintain. You can check below steps.

Define the key/values of appsettings in the pipeline variables. enter image description here

You can aslo define the variables in the YAML file:

variables:
  key1: value1
  key2: value2

Then then refer to variables in appsettings field of app service deployment task

- task: AzureRmWebAppDeployment@4
  inputs:
    AppSettings: '-key1 $(key1) -key2 $(key2)'

Another workaround is to use Azure App Service Settings task to add the appsettings to the function app. (You don't need to define appSettings field for app deployment task if App Service Settings task is used to add appsettings)

- task: AzureAppServiceSettings@0
  displayName: Azure App Service Settings
  inputs:
    azureSubscription: $(azureSubscription)
    appName: $(FunctionApp_Name)
    appSettings: |
      [
        {
          "name": "key1",
          "value": "$(Key1)",
          "slotSetting": false
        },
        {
          "name": "key2",
          "value": "$(Key2)",
          "slotSetting": false
        },
        {
          "name": "MYSQL_DATABASE_NAME",
          "value": "$(DB_Name)", 
          "slotSetting": false
        }

So by using above workarounds, you only need to change the values in the pipeline's variables to change the appsettings for function app.

You can also use terraform to add appsettings to you function app. Please check out the detailed steps in this tutorial Automating infrastructure deployments in the Cloud with Terraform and Azure Pipelines.

1
votes

While looking for a solution i found this newly available ellipsis button next to the appsettings box. Clicking on it opens a new dialog where i can add app settings in key value pairs in a table format (similar to variable groups), each in separate line and easily maintainable (each setting can be deleted). On clicking OK it generates a string of all parameters.

I think this should be good enough to maintain appSettings for the function app.

Below is the screenshot

enter image description here