6

I am trying to add app settings to my Azure Website via the JSON template files as part of the Azure Resource Manager.

In an Azure Resource template json file, there are examples for creating connectionStrings directly from the JSON template file with a sub-dependency of type 'config' with properties for 'connectionStrings' as in the final example here http://haishibai.blogspot.co.uk/2014/09/tutorial-building-azure-template.html I have also checked in the website schema definition for websites here http://schema.management.azure.com/schemas/2014-06-01/Microsoft.Web.json#/definitions/sites and cannot see that it is possible.

Is it possible to define a websites app settings for resource manager deployments from the JSON template file? And if so any links or details would be greatly appreciated.

(I have already tried properties of appSettings inside the config resource and inside the website resource)

Damien Pontifex
  • 1,222
  • 1
  • 15
  • 27

4 Answers4

18

I have a sample that shows how to do this here. It looks like this:

    {
      "apiVersion": "2014-11-01",
      "name": "appsettings",
      "type": "config",
      "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
      ],
      "properties": {
        "AppSettingKey1": "Some value",
        "AppSettingKey2": "My second setting",
        "AppSettingKey3": "My third setting"
      }
    }

Please make sure you use the newest 2014-11-01 API, as the way it deals with app settings is a bit different from the older API.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • Thanks for this David. Works, but it makes the app settings and connection strings have a first letter lowercase. i.e. in this example appSettingKey1 is what shows up in the portal. Or I have STORAGE_ACCOUNT_NAME comes up as sTORAGE_ACCOUNT_NAME. Is this usual? Or am I still doing something wrong? – Damien Pontifex Dec 24 '14 at 16:43
  • It's a bug, you're not doing anything wrong. However, it's harmless as the bad casing is not used at runtime for the settings. It's only the API that returns them that way. It'll be fixed in the future, but for now you can ignore this quirk :) – David Ebbo Dec 24 '14 at 20:41
  • @DavidEbbo is it possible to set built-in properties such as `AlwaysOn` / `WebSockets` etc.? Also, is it possible to setup a local git deployment using Azure templates? – James Aug 28 '15 at 13:45
  • @DavidEbbo just watched your excellent [Advanced deployment strategies for Azure Web Apps using Resource Manager templates](https://channel9.msdn.com/Events/Build/2015/2-620) talk and had no idea [resources.azure.com](https://resources.azure.com) existed! I can now see how I can configure those settings, although it's still not entirely clear about the local git repo - exploring the API on an existing site that has a local git deployment I can see the repo URL is set to the *.scm.azurewebsites.net URL, is it just a case of applying this from a template? – James Aug 28 '15 at 15:54
  • Probably best not to fork this one question into a bunch of others. :) Can you start a new one, or post to https://social.msdn.microsoft.com/Forums/azure/en-US/home?forum=windowsazurewebsitespreview? I can help there. Thanks! – David Ebbo Aug 28 '15 at 17:47
11

With thanks to Simon Pedersen - properties/siteConfig/appSettings works as of November 2015.

{
    "apiVersion": "2014-06-01",
    "name": "[concat(parameters('siteName'),copyIndex())]",
    "type": "Microsoft.Web/sites",
    "location": "[parameters('siteLocations')[copyIndex()]]",
    "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
    },
    "dependsOn": [
        "[concat('Microsoft.Web/serverfarms/', concat(parameters('hostingPlanName'),copyIndex()))]",
        "[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]"
    ],
    "properties": {
        "name": "[concat(parameters('siteName'),copyIndex())]",
        "serverFarm": "[concat(parameters('hostingPlanName'),copyIndex())]",
        "siteConfig": {
            "appSettings": [
                {
                    "name": "AzureStorageAccount",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('newStorageAccountName'),';AccountKey=',listKeys(variables('storageid'),'2015-05-01-preview').key1)]"
                }
            ]
        }
    },
    "copy": {
        "name": "siteCopy",
        "count": "[parameters('numberOfSites')]"
    }
}
Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
Chui Tey
  • 5,436
  • 2
  • 35
  • 44
3

Here is the solution for the latest release 2014-06-01 version of API.

"resources": [
    {
        "apiVersion": "2014-06-01",
        "name": "[parameters('webSiteName')]",
        "type": "Microsoft.Web/sites",
        "location": "[parameters('webSiteLocation')]",
        "tags": {
            "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('webSiteHostingPlanName'))]": "Resource",
            "displayName": "WebSite"
        },
        "dependsOn": [
            "[concat('Microsoft.Web/serverfarms/', parameters('webSiteHostingPlanName'))]"
        ],
        "properties": {
            "name": "[parameters('webSiteName')]",
            "serverFarm": "[parameters('webSiteHostingPlanName')]"
        },
        "resources": [
            {
                "apiVersion": "2014-04-01",
                "name": "MSDeploy",
                "type": "extensions",
                "dependsOn": [
                    "[concat('Microsoft.Web/Sites/', parameters('webSiteName'))]"
                ],
                "properties": {
                    "packageUri": "[concat(parameters('dropLocation'), '/', parameters('webSitePackage'), parameters('dropLocationSasToken'))]",
                    "dbType": "None",
                    "connectionString": "",
                    "setParameters": {
                        "IIS Web Application Name": "[parameters('webSiteName')]"
                    }
                }
            },
            {
                "apiVersion": "2014-04-01",
                "name": "web",
                "type": "config",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]"
                ],
                "properties": {
                    "connectionStrings": [
                        {
                            "ConnectionString": "AzureWebJobsStorage",
                            "Name": "CustomConnectionString1"
                        },
                        {
                            "ConnectionString": "AzureWebJobsStorage",
                            "Name": "CustomConnectionString2"
                        }
                    ],
                    "appSettings": [
                        {
                            "Name": "Key1",
                            "Value": "Value1"
                        },
                        {
                            "Name": "Key2",
                            "Value": "Value2"
                        }
                    ]
                }
            }
        ]
    },
infinity
  • 1,900
  • 4
  • 29
  • 48
  • What do you mean by "latest release"? You're using "2014-04-01" and "2014-06-01", David explicitly said to use "2014-11-01". – BenV Feb 12 '15 at 17:55
  • Thanks for pointing out.. I updated my answer! My solution is for 2014-06-01 version of the API which is the default version set in the template file when I created the deployment project. (I have Azure SDK 2.5 installed) – infinity Feb 12 '15 at 19:05
3

Adding as a sub/child resource fails to work using the later API's, however adding a "siteConfig" property with an "appSettings" element, as stated above, seems to work. I am using the API Version 2016-03-01

{
        "type": "Microsoft.Web/sites",
        "name": "[variables('webappName')]",
        "apiVersion": "2016-03-01",
        "location": "[parameters('location')]",
        "tags": "[parameters('tags')]",
        "kind": "app",
        "properties": {
            "name": "[variables('webappName')]",
            "serverFarmId": "[variables('targetResourceId')]",
            "hostingEnvironment": "[parameters('hostingEnvironment')]",
            "netFrameworkVersion": "[parameters('netFrameworkVersion')]",
            "use32BitWorkerProcess": false,
            "webSocketsEnabled": true,
            "alwaysOn": true,
            "managedPipelineMode": "integrated",
            "clientAffinityEnabled": true,
            "hostNameSslStates": [
                {
                    "name": "[variables('hostName')]",
                    "sslState": "SniEnabled",
                    "thumbprint": "[parameters('certThumb')]",
                    "ipBasedSslState": "NotConfigured",
                    "hostType": "Standard"
                }
            ],
            "siteConfig": {
               "appSettings": "[variables('appSettings')]"
            }
        },
        "dependsOn": [
            "[concat('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
        ],
        "resources": []
    }

And my variable looks like this.....

"appSettings": [
            {
                "name": "WEBSITE_NODE_DEFAULT_VERSION",
                "value": "8.9.3"
            },
            {
                "name": "WEBSITE_PRIVATE_EXTENSIONS",
                "value": "0"
            },
            {
                "name": "MobileAppsManagement_EXTENSION_VERSION",
                "value": "latest"
            },
            {
                "name": "WEBSITE_LOAD_CERTIFICATES",
                "value": "*"
            }
        ]
Basher 590
  • 166
  • 1
  • 4