[英]Azure ARM deploy App Service Plan based on input parameters
我正在嘗試創建一個包含App Service計划和App Service的ARM模板,但是如果未設置參考現有App Service計划的可選參數,則僅在其中創建App Service計划的模板。
因此,ARM應該僅使用作為參數給出的現有App Service計划為App Service創建一個App Service計划。
那怎么可能呢?
解
這是有效的壓軸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"
}
}
}
在您的情況下,您應該向dependsOn
添加dependsOn
屬性:
dependsOn: [
"[variables('serviceplanName')]"
]
這樣,如果需要創建它,它將等待它完成。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.