user2197446
user2197446

Reputation: 1146

Deploy Azure Batch via ARM template with application upload

I built out an Azure Batch Account via the UI (Portal) and exported the template after I got everything working the way I wanted it.

Now I'm trying to deploy this ARM template via Visual Studio 2019 and keep getting the following error:

The specified application package does not exist.

The ARM template looks good and I've reconciled it with Microsoft.Batch batchAccounts/pools template reference. I did this to verify that the template allows for applicationPackages element.

The specific portion of the template causing my issue is as follows:

        "applicationPackages": [
      {
        "id": "[concat(resourceId('Microsoft.Batch/batchAccounts', parameters('batchAccounts_baeast909_name')), '/applications/logparser')]",
        "version": "2.2"
      },
      {
        "id": "[concat(resourceId('Microsoft.Batch/batchAccounts', parameters('batchAccounts_baeast909_name')), '/applications/powershellscripts')]",
        "version": "1.0"
      }
    ]

I was hoping this is would be as simple as placing the application zips in a directory called applications and running everything again. Alas it wasn't and the deployment failed with the same error.

One of the comments asked why I would be doing this. The answer to this is I'm running a Custom Activity out of Azure Data Factory V2 (ADFv2.) The custom activity transforms WebLogs via a executable called LogParser.exe That executable is loaded as an application to the Batch Account as you see below. I also added the PowerShell Scripts that tie everything together as an application.

Applications loaded to Batch Account

I was hoping for a solution similar to deploying a Web App that is detailed here: Deploy Azure Web App Package using ARM

So my questions are: Can the applications zips be deployed at the same time as I am deploying the ARM template? If they can not, when do I deploy them, and how do I automate that process?

application.json:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "configuration": {
      "type": "object",
      "metadata": {
        "description": "Configuration for this resource"
      }
    },
    "pools_1_password": {
      "type": "SecureString"
    },
    "batchAccounts_baeast909_name": {
      "defaultValue": "baeast909",
      "type": "String"
    },
    "storageAccounts_storageaccount909_externalid": {
      "defaultValue": "/subscriptions/subguid/resourceGroups/resourcegroup909/providers/Microsoft.Storage/storageAccounts/storageaccount909",
      "type": "String"
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Batch/batchAccounts",
      "apiVersion": "2017-09-01",
      "name": "[parameters('batchAccounts_baeast909_name')]",
      "location": "eastus2",
      "tags": {
        "displayname": "[parameters('configuration').displayName]",
        "department": "[parameters('configuration').department]",
        "group": "[parameters('configuration').group]",
        "environment": "[parameters('configuration').environment]",
        "primaryOwner": "[parameters('configuration').primaryOwner]",
        "secondaryOwner": "[parameters('configuration').secondaryOwner]",
        "version": "[parameters('configuration').version]",
        "ms-resource-usage": "azure-cloud-shell"
      },
      "properties": {
        "autoStorage": {
          "storageAccountId": "[parameters('storageAccounts_storageaccount909_externalid')]"
        },
        "poolAllocationMode": "BatchService"
      }
    },
    {
      "type": "Microsoft.Batch/batchAccounts/pools",
      "apiVersion": "2017-09-01",
      "name": "[concat(parameters('batchAccounts_baeast909_name'), '/1')]",
      "dependsOn": [
        "[resourceId('Microsoft.Batch/batchAccounts', parameters('batchAccounts_baeast909_name'))]"
      ],
      "properties": {
        "vmSize": "STANDARD_A1",
        "interNodeCommunication": "Disabled",
        "maxTasksPerNode": 1,
        "taskSchedulingPolicy": {
          "nodeFillType": "Spread"
        },
        "deploymentConfiguration": {
          "virtualMachineConfiguration": {
            "imageReference": {
              "publisher": "microsoftwindowsserver",
              "offer": "windowsserver",
              "sku": "2016-datacenter",
              "version": "latest"
            },
            "nodeAgentSkuId": "batch.node.windows amd64",
            "dataDisks": [
              {
                "lun": 0,
                "caching": "ReadWrite",
                "diskSizeGB": 100,
                "storageAccountType": "Standard_LRS"
              }
            ]
          }
        },
        "scaleSettings": {
          "fixedScale": {
            "targetDedicatedNodes": 1,
            "targetLowPriorityNodes": 0,
            "resizeTimeout": "PT15M"
          }
        },
        "userAccounts": [
          {
            "name": "jborn",
            "elevationLevel": "NonAdmin",
            "password": "[parameters('pools_1_password')]"
          }
        ],
        "applicationPackages": [
          {
            "id": "[concat(resourceId('Microsoft.Batch/batchAccounts', parameters('batchAccounts_baeast909_name')), '/applications/logparser')]",
            "version": "2.2"
          },
          {
            "id": "[concat(resourceId('Microsoft.Batch/batchAccounts', parameters('batchAccounts_baeast909_name')), '/applications/powershellscripts')]",
            "version": "1.0"
          }
        ]
      }
    }
  ]
}

application.parameters.json:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "configuration": {
      "value": {
        "displayName": "A Batch Account",
        "department": "IT",
        "group": "Development",
        "environment": "dev",
        "primaryOwner": "[email protected]",
        "secondaryOwner": "[email protected]",
        "version": "1.0"
      }
    },
    "pools_1_password": {
      "reference": {
        "keyVault": {
          "id": "/subscriptions/subguid/resourceGroups/rgn00119/providers/Microsoft.KeyVault/vaults/keyvault909"
        },
        "secretName": "azureAdmin"
      }
    },
    "batchAccounts_jc00mdpbageu2d99_name": {
      "value": "jc00mdpbageu2d99"
    },
    "storageAccounts_jc00mdpstgeud99_externalid": {
      "value": "/subscriptions/subguid/resourceGroups/rgn00119/providers/Microsoft.Storage/storageAccounts/storageAccount909"
    }
  }
}

Upvotes: 0

Views: 1035

Answers (1)

AmanGarg-MSFT
AmanGarg-MSFT

Reputation: 1153

Please follow the below steps to download and deploy an ARM template using Visual Studio 2019:

  1. Fill the details for creating a Azure Batch account and click on "Download a template for automation"

enter image description here

  1. Download the zip

enter image description here

Edit: In order to create a batch pool using ARM template, you would first have to create an Application Package using Azure CLI and reference this from your ARM template for creating a Batch Pool

# Upload and register your archive as application package
az batch application package create \
  --resource-group testrg01 \
  --name test01 \
  --application-id app01 \
  --package-file myapp-exe.zip \
  --version 1.0
# Set this version of package as default version
az batch application set \
  --resource-group testrg01 \
  --name test01 \
  --application-id app01 \
  --default-version 1.0

References:

https://tsmatz.wordpress.com/2017/12/12/essential-azure-batch-with-azure-cli/

https://learn.microsoft.com/bs-latn-ba/cli/azure/batch/application/package?view=azure-cli-latest

https://learn.microsoft.com/en-us/azure/batch/batch-cli-templates

Hope this helps!

Upvotes: 1

Related Questions