Create Azure Storage Queue using ARM template

ARM gradually adds support for creation of sub-resources of storage accounts:

  • storage queues in version 2019-06-01
  • containers in version 2018-02-01
  • file shares in version 2019-04-01

ARM template describing a storage account with a queue:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "environment": {
      "type": "string",
      "allowedValues": [
        "dev",
        "test",
        "prod"
      ]
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "storageAccountSkuName": {
      "type": "string",
      "defaultValue": "Standard_LRS"
    },
    "storageAccountSkuTier": {
      "type": "string",
      "defaultValue": "Standard"
    }
  },
  "variables": {
    "uniquePart": "[take(uniqueString(resourceGroup().id), 4)]",
    "storageAccountName": "[concat('mystorageaccount', variables('uniquePart'), parameters('environment'))]",
    "queueName": "myqueue"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('storageAccountName')]",
      "location": "[parameters('location')]",
      "apiVersion": "2019-06-01",
      "sku": {
        "name": "[parameters('storageAccountSkuName')]",
        "tier": "[parameters('storageAccountSkuTier')]"
      },
      "kind": "StorageV2",
      "properties": {},
      "resources": [
        {
          "name": "[concat('default/', variables('queueName'))]",
          "type": "queueServices/queues",
          "apiVersion": "2019-06-01",
          "dependsOn": [
            "[variables('storageAccountName')]"
          ],
          "properties": {
            "metadata": {}
          }
        }
      ]
    }
  ]
}

Before the support was added, the resources could be created via other means (best to worst):

  1. during deployment of ARM templates, using tricks to execute arbitrary code
  2. during deployment overall, using Azure CLI called by the deployment tool
  3. in application startup code, using the Azure SDK

The option number two for queues uses the az storage queue create command.

You can add in the Azure CLI task in Azure DevOps, hook up the subscription and the give it an inline script like so:

call az storage queue create -n "awesome-queue-1" --connection-string "$(storageAccountConnectionString)"

If you're using a Windows build agent then you need to include the call to ensure that multiple lines are executed. If you're on a Linux agent then call can be omitted.

That connection string can be exported from your ARM template as an output parameter and then sucked into the DevOps variables using ARM Outputs.

-- Simon Timms: Creating Storage Queues in Azure DevOps @ Western Devs


Seems that support for it is available, but maybe not officially as of 29.07.2020. The documentation is available at: https://learn.microsoft.com/en-us/azure/templates/microsoft.storage/storageaccounts/queueservices/queues

Here is what worked for me:

"variables": {
    "storageAccountName": "[toLower(concat('sa', 'demo', parameters('environmentName')))]"
},
"resources": [
    {
        "type": "Microsoft.Storage/storageAccounts",
        "name": "[variables('storageAccountName')]",
        "location": "[parameters('location')]",
        "apiVersion": "2019-06-01",
        "sku": {
            "name": "[parameters('storageAccountType')]"
        },
        "kind": "StorageV2",
        "properties": {}
    },
    {
        "name": "[concat(variables('storageAccountName'), '/default/myqueue01')]",
        "type": "Microsoft.Storage/storageAccounts/queueServices/queues",
        "apiVersion": "2019-06-01",
        "dependsOn": [
            "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
        ],
        "properties": {
            "metadata": {}

        }
    }
],

Let me know if it works for you.


No, you can't create Azure Storage Queues through ARM templates but I doubt it is necessary because when you use e. g. the .NET SDK to interact with the queue, you can call the CreateIfNotExistsAsync() method to create it. Example:

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

// Retrieve a reference to a container.
CloudQueue queue = queueClient.GetQueueReference("myqueue");

// Create the queue async if it doesn't already exist
await queue.CreateIfNotExistsAsync();

Source