Azure资源管理器模板网站应用设置

时间:2014-12-22 16:17:35

标签: azure azure-web-sites azure-resource-manager

我正在尝试通过JSON模板文件将应用程序设置添加到我的Azure网站,作为Azure资源管理器的一部分。

在Azure资源模板json文件中,有一些示例可以直接从JSON模板文件创建connectionStrings,其子类依赖性为' config'具有' connectionStrings'的属性与此处的最后一个示例http://haishibai.blogspot.co.uk/2014/09/tutorial-building-azure-template.html一样,我还检查了网站的网站架构定义http://schema.management.azure.com/schemas/2014-06-01/Microsoft.Web.json#/definitions/sites,但无法看到它是可能的。

是否可以从JSON模板文件中为资源管理器部署定义网站应用程序设置?如果是这样,任何链接或细节将不胜感激。

(我已经在配置资源和网站资源中尝试了appSettings的属性)

4 个答案:

答案 0 :(得分:15)

我有一个示例,说明如何执行此操作here。它看起来像这样:

    {
      "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"
      }
    }

请确保您使用最新的2014-11-01 API,因为它处理应用设置的方式与旧版API略有不同。

答案 1 :(得分:9)

感谢Simon Pedersen - properties/siteConfig/appSettings自2015年11月开始工作。

{
    "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')]"
    }
}

答案 2 :(得分:2)

以下是最新版本 2014-06-01版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"
                        }
                    ]
                }
            }
        ]
    },

答案 3 :(得分:2)

添加为子资源/子资源无法使用更高版本的API,但是如上所述,添加带有“ appSettings”元素的“ siteConfig”属性似乎可行。我正在使用API​​版本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": []
    }

我的变量看起来像这样.....

"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": "*"
            }
        ]