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
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"
}
]
}
}
]
},
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')]"
}
}
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.
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": "*"
}
]