2017-09-25 42 views
0

在我的天藍色模板中,如果我希望將我的webapp部署在專用的應用服務計劃上,或者我想要使用共享的應用服務計劃,那麼我有一個條件。Azure ARM條件在驗證過程中失敗

如果我選擇不使用專用的計劃,我想忽略: - 第一部分,在那裏我部署專門的應用服務計劃 - 第二部分,在那裏我部署Web應用程序,並使用專用服務計劃。

然後使用第三部分並使用共享應用程序計劃部署Web應用程序。

下面是我的ARM模板的摘錄。

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
    "_artifactsLocation": { 
     "type": "string" 
    }, 
    "_artifactsLocationSasToken": { 
     "type": "string" 
    }, 
    "environmentConfiguration": { 
     "type": "object" 
    } 
    }, 
    "variables": {}, 
    "resources": [ 
    { 
     "comments": "App Service Plan hosting all websites", 
     "apiVersion": "2017-05-10", 
     "name": "AppServicePlan", 
     "type": "Microsoft.Resources/deployments", 
     "condition": "[equals(parameters('environmentConfiguration').serverFarm.useDedicatedPlan, 'true')]", 
     "properties": { 
     "mode": "Incremental", 
     "templateLink": { 
      "uri": "[concat(parameters('_artifactsLocation'),'/Microsoft.Web/Asp.json',parameters('_artifactsLocationSasToken'))]", 
      "contentVersion": "1.0.0.0" 
     }, 
     "parameters": { 
      "environmentConfiguration": { 
      "value": "[parameters('environmentConfiguration')]" 
      } 
     } 
     } 
    }, 
    { 
     "comments": "Web apps on dedicated plan", 
     "apiVersion": "2017-05-10", 
     "name": "[concat('WebAppsDedicatedPlan-',parameters('environmentConfiguration').webApp.webApps[copyIndex()].name)]", 
     "type": "Microsoft.Resources/deployments", 
     "condition": "[equals(parameters('environmentConfiguration').serverFarm.useDedicatedPlan, 'true')]", 
     "copy": { 
     "name": "webAppCopy", 
     "count": "[length(parameters('environmentConfiguration').webApp.webApps)]" 
     }, 
     "dependsOn": [ 
     "[resourceId('Microsoft.Resources/deployments', 'AppServicePlan')]" 
     ], 
     "properties": { 
     "mode": "Incremental", 
     "templateLink": { 
      "uri": "[concat(parameters('_artifactsLocation'),'/Microsoft.Web/WebApp.json',parameters('_artifactsLocationSasToken'))]", 
      "contentVersion": "1.0.0.0" 
     }, 
     "parameters": { 
      "environmentConfiguration": { 
      "value": "[parameters('environmentConfiguration')]" 
      }, 
      "dependencies": { 
      "value": { 
      "webAppInfo": "[parameters('environmentConfiguration').webApp.webApps[copyIndex()]]", 
      "serverFarmId": "[reference('AppServicePlan').outputs.serverFarmId.value]" 
      } 
      } 
     } 
     } 
    }, 
    { 
     "comments": "Web apps on shared plan", 
     "apiVersion": "2017-05-10", 
     "name": "[concat('WebAppsOnSharedPlan-',parameters('environmentConfiguration').webApp.webApps[copyIndex()].name)]", 
     "type": "Microsoft.Resources/deployments", 
     "condition": "[equals(parameters('environmentConfiguration').serverFarm.useDedicatedPlan, 'false')]", 
     "copy": { 
     "name": "webAppCopy", 
     "count": "[length(parameters('environmentConfiguration').webApp.webApps)]" 
     }, 
     "dependsOn": [], 
     "properties": { 
     "mode": "Incremental", 
     "templateLink": { 
      "uri": "[concat(parameters('_artifactsLocation'),'/Microsoft.Web/WebApp.json',parameters('_artifactsLocationSasToken'))]", 
      "contentVersion": "1.0.0.0" 
     }, 
     "parameters": { 
      "environmentConfiguration": { 
      "value": "[parameters('environmentConfiguration')]" 
      }, 
      "dependencies": { 
      "value": { 
       "webAppInfo": "[parameters('environmentConfiguration').webApp.webApps[copyIndex()]]", 
       "serverFarmId": "[resourceId('sharedResources','Microsoft.Web/serverfarms','sharedasp')]" 
      } 
      } 
     } 
     } 
    } 
    ], 
    "outputs": {} 
} 

什麼是工作:如果刪除的應用服務計劃的部分條件,我要求不使用專用的計劃,我的Web應用程序所使用的共享計劃部署。 (應用程序服務計劃也已部署)。

什麼不工作:如果我讓在App服務計劃部分的情況時,我問不使用專用的計劃,驗證失敗,出現以下消息不部署:

2017-09-25T11:55:49.7343682Z Creating deployment parameters. 
2017-09-25T11:55:49.7373683Z The detected encoding for file 
'd:\a\r1\a\output\iac\myapp.json' is 'utf-8' 
2017-09-25T11:55:49.7373683Z The detected encoding for file 
'd:\a\r1\a\output\iac\myapp.parameters.qa.json' is 'utf-8' 
2017-09-25T11:55:49.7373683Z Starting Deployment. 
2017-09-25T11:55:51.3725072Z There were errors in your deployment. 
Error code: InvalidTemplate. 2017-09-25T11:55:51.3735078Z 
##[error]Deployment template validation failed: 'The template resource 'Microsoft.Resources/deployments/WebAppsDedicatedPlan-appadmin' 
reference to 'Microsoft.Resources/deployments/AppServicePlan' requires 
an API version. Please see https://aka.ms/arm-template for usage 
details.'. 2017-09-25T11:55:51.3735078Z ##[error]Task failed while 
creating or updating the template deployment. 
2017-09-25T11:55:51.4295112Z ##[section]Finishing: Azure Deployment: 
Update resource group 

如何我可以解決這個問題嗎?

回答

1

「的模板資源 'Microsoft.Resources /部署/ WebAppsDedicatedPlan-appadmin' 參考 'Microsoft.Resources /部署/ AppServicePlan' 需要 的API版本。

該錯誤提供了。檢查docs以便更好地理解。這就是爲什麼它出錯:

指定資源的API版本。如果資源未在相同模板中供應,請包括此參數。通常情況下,格式爲yyyy-mm-dd。

因此,您需要將API版本添加到在模板外部創建的資源的參考函數中