gpt4 book ai didi

Azure ARM根据输入参数部署应用服务计划

转载 作者:行者123 更新时间:2023-12-02 08:04:26 24 4
gpt4 key购买 nike

我正在尝试创建一个包含应用服务计划和应用服务的 ARM 模板,但只有在未设置引用现有应用服务计划的可选参数时才会创建应用服务计划。

因此,ARM 应该为应用服务创建一个应用服务计划,或者仅使用作为参数给出的现有应用服务计划。

这怎么可能做到?

解决方案

这是最终可用的 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"
}
}
}

最佳答案

在您的情况下,您应该向 webApp 添加一个 dependsOn 属性:

dependsOn: [
"[variables('serviceplanName')]"
]

这样,如果需要创建它,它将等待它完成。

关于Azure ARM根据输入参数部署应用服务计划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47747840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com