使用Azure Resource Manager模板将现有Web Service计划附加到新网站

时间:2015-10-02 07:02:22

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

我正在尝试使用Azure资源管理器自动化网站部署。网站创建和代码部署工作正常,但我无法将新网站附加到现有的虚拟主机计划。

我正在使用2015-08-01 API,从不同的例子中我认为这个模板应该有用(它没有......):

部署在" Microsoft.Web / sites / config"并且该网站正在分配一个新的默认免费托管计划。

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "siteName": {
        "type": "string"
    },
    "subscriptionId": {
        "type": "string"
    },
    "setting1": {
        "type": "string"
    },
    "setting2": {
        "type": "string"
    }
},
"resources": [
    {
        "apiVersion": "2015-08-01",
        "type": "Microsoft.Web/sites",
        "name": "[parameters('siteName')]",
        "location": "[resourceGroup().location]",
        "properties": {
            "serverFarmId ": "/subscriptions/xxxxxx/resourceGroups/xxxxxx/providers/Microsoft.Web/serverfarms/xxxxxx"
        },
        "resources": [
            {
                "apiVersion": "2015-08-01",
                "name": "web",
                "type": "config",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
                ],
                "properties": {
                    "phpVersion": "off",
                    "netFrameworkVersion": "v4.6",
                    "use32BitWorkerProcess": false,
                    "webSocketsEnabled": true,
                    "alwaysOn": true,
                    "requestTracingEnabled": false,
                    "httpLoggingEnabled": false,
                    "logsDirectorySizeLimit": 40,
                    "detailedErrorLoggingEnabled": false,
                    "appSettings": [
                        {
                            "Name": "setting1",
                            "Value": "Value1"
                        },
                        {
                            "Name": "setting2",
                            "Value": "Value2"
                        }
                    ]
                }
            },
            {
                "apiVersion": "2015-08-01",
                "type": "extensions",
                "name": "MSDeploy",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
                ],
                "properties": {
                    "packageUri": "xxxxxxxx",
                    "dbType": "None",
                    "connectionString": ""
                }
            }
        ]
    }
],
"outputs": {
    "siteUri": {
        "type": "string",
        "value": "[concat('http://',reference(resourceId('Microsoft.Web/sites', parameters('siteName'))).hostNames[0])]"
    }
}

}

1 个答案:

答案 0 :(得分:2)

我最终回到2014-06-01 API并对脚本进行了一些调整,能够做到我想要的。

提供脚本以供将来参考。

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "siteName": {
        "type": "string"
    },
    "subscriptionId": {
        "type": "string"
    },
    "hostingPlanName": {
        "type": "string"
    },
    "setting1": {
        "type": "string"
    },
    "setting2": {
        "type": "string"
    }
},
"resources": [
    {
        "apiVersion": "2014-06-01",
        "type": "Microsoft.Web/sites",
        "name": "[parameters('siteName')]",
        "location": "[resourceGroup().location]",
        "dependsOn": [

        ],
        "properties": {
            "name": "[parameters('siteName')]",
            "serverFarm": "[parameters('hostingPlanName')]"
        },
        "resources": [
            {
                "apiVersion": "2014-06-01",
                "name": "web",
                "type": "config",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]",
                    "[concat('Microsoft.Web/Sites/', parameters('siteName'), '/Extensions/MSDeploy')]"
                ],
                "properties": {
                    "phpVersion": "off",
                    "netFrameworkVersion": "v4.6",
                    "use32BitWorkerProcess": false,
                    "webSocketsEnabled": true,
                    "alwaysOn": true,
                    "requestTracingEnabled": false,
                    "httpLoggingEnabled": false,
                    "logsDirectorySizeLimit": 40,
                    "detailedErrorLoggingEnabled": false
                }
            },
            {
                "apiVersion": "2014-11-01",
                "name": "appsettings",
                "type": "config",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]",
                    "[concat('Microsoft.Web/Sites/', parameters('siteName'), '/Extensions/MSDeploy')]"

                ],
                "properties": {
                    "Setting1": "[parameters('setting1')]",
                    "Setting2": "[parameters('setting2')]"
                }
            },
            {
                "apiVersion": "2015-08-01",
                "type": "extensions",
                "name": "MSDeploy",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
                ],
                "properties": {
                    "packageUri": "https://xxxxx.zip",
                    "dbType": "None",
                    "connectionString": ""
                }
            }
        ]
    }
]

}