我正在尝试创建包含应用服务计划和应用服务的ARM模板,但如果未设置参考现有应用服务计划的可选参数,则仅创建应用服务计划
因此,ARM应该为App Service创建一个App Service Plan,只使用作为参数提供的现有App Service Plan。
这怎么可能呢?
解
以下是适用的最终ARM模板
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"currentServiceplanId": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "Optional. Use an existing serviceplan for deployment"
}
},
"serviceplanSkuName": {
"type": "string",
"defaultValue": "B1",
"allowedValues": [
"B1",
"B2",
"B3",
"S1",
"S2",
"S3",
"P1",
"P2",
"P3",
"P4"
],
"metadata": {
"description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
}
}
},
"variables": {
"prefix": "setup05",
"serviceplanName": "[concat(variables('prefix'), 'serviceplan')]",
"serviceplanId": "[variables('serviceplanIdSelector')[string(equals(length(parameters('currentServiceplanId')), 0))]]",
"serviceplanIdSelector": {
"true": "[resourceId('Microsoft.Web/serverfarms', variables('serviceplanName'))]",
"false": "[parameters('currentServiceplanId')]"
},
"api-appName": "[concat(variables('prefix'), 'api-app')]"
},
"resources": [
{
"name": "[variables('serviceplanName')]",
"condition": "[equals(length(parameters('currentServiceplanId')), 0)]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"sku": {
"name": "[parameters('serviceplanSkuName')]"
},
"properties": {
"name": "[variables('serviceplanName')]",
"numberOfWorkers": 1
}
},
{
"name": "[variables('api-appName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('serviceplanName'))]"
],
"properties": {
"name": "[variables('api-appName')]",
"serverFarmId": "[variables('serviceplanId')]"
}
}
],
"outputs": {
"ApiDefaultHostname": {
"value": "[reference(variables('api-appName')).defaultHostName]",
"type": "string"
},
"ApiAppName": {
"value": "[variables('api-appName')]",
"type": "string"
}
}
}
答案 0 :(得分:3)
在您的情况下,您应该向webApp添加dependsOn
属性:
dependsOn: [
"[variables('serviceplanName')]"
]
这样,如果需要创建,它将等待它完成。