验证期间Azure ARM条件失败

时间:2017-09-25 12:16:52

标签: azure azure-resource-manager

在我的azure模板中,如果我希望将webapps部署在专用的应用服务计划上,或者我想使用共享的应用服务计划,我会选择一个条件。

如果我选择不使用专门的计划,我想忽略: - 我部署专用应用服务计划的第一部分 - 我部署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": {}
}

工作原理:如果我删除了“应用服务计划”部分中的条件,并且我要求不使用专用计划,则使用共享计划部署我的网络应用程序。 (还部署了应用服务计划)。

什么不起作用:当我要求不使用专用计划时,我让App Service Plan部分中的条件不部署它,验证失败,并显示以下消息:

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 个答案:

答案 0 :(得分:1)

  

'模板资源   'Microsoft.Resources /部署/ WebAppsDedicatedPlan-appadmin'   引用'Microsoft.Resources / deployments / AppServicePlan'需要   API版本。

错误就是这样。检查docs以便更好地理解。这就是它出错的原因:

指定资源的API版本。在未在同一模板中配置资源时包括此参数。通常,格式为yyyy-mm-dd。

因此,您需要将api版本添加到参考函数中,以便在模板外部创建的资源