0
votes

In my azure template I have a condition where I chose if I want my webapps deployed on a dedicated App Service Plan or if I want to use a shared App Service plan.

If I chose to not use a dedicated plan I want to ignore: - the first section where I deploy the dedicated App Service Plan - the second section where I deploy the Web Apps and use the dedicated Service Plan.

The third section is then used and deploy the web apps with a shared app plan.

Below is an extract of my ARM template.

{
  "$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": {}
}

What is working: If I remove the condition in the App Service Plan section and I ask to not use the dedicated plan, my web apps are deployed using the shared plan. (The app service plan is also deployed).

What is not working: If I let the condition in the App Service Plan section to not deploy it when I ask for to not use the dedicated plan the validation fails with the following message:

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

How can I solve this issue?

1

1 Answers

1
votes

'The template resource 'Microsoft.Resources/deployments/WebAppsDedicatedPlan-appadmin' reference to 'Microsoft.Resources/deployments/AppServicePlan' requires an API version.

The error gives that away. Check docs for better understanding. This is why it errors out:

API version of the specified resource. Include this parameter when the resource is not provisioned within same template. Typically, in the format, yyyy-mm-dd.

So you need to add api version to the reference function for resources created outside of the template