Create Azure Storage Containers with ARM templates

While you can create an Azure Storage account with an ARM template very quickly, it’s not been possible to create anything inside this storage account, such as blob containers, tables, queues, using the same ARM template. If you wanted to do this, you either needed to look at running scripts after your template completes, or using something like Terraform, which does allow you to create these things.

However, a recent update to the ARM schema means you can now create Blob containers in your template. We’re still waiting for tables, queues and shares, but this is a start. Unfortunately, the ARM reference docs don’t seem to have been updated to show how to do this, so I’ll show you how.

You can see some documentation under the ARM REST API entry for the storage resource povider, as it’s these REST API’s that translate into ARM templates.

Create Blob Containers

The blob container resource is a sub-resource of the storage account. When you create a storage account, you can now specify an array of resources, which is where you define the containers you want to create. We are then going to specify objects of type “blobServices/containers”, and make sure to use an API version of 2018-02-01 or later.

In the example below, we are creating a storage account with two containers.

{
    "type": "Microsoft.Storage/storageAccounts",
    "apiVersion": "2018-02-01",
    "name": "[parameters('StorageAccountName')]",
    "location": "[resourceGroup().location]",
    "tags": {
        "displayName": "[parameters('StorageAccountName')]"
    },
    "sku": {
        "name": "Standard_LRS"
    },
    "kind": "StorageV2",
    "properties": {},
    "resources": [
        {
            "type": "blobServices/containers",
            "apiVersion": "2018-03-01-preview",
            "name": "[concat('default/', parameters('Container1Name'))]",
            "dependsOn": [
                "[parameters('StorageAccountName')]"
            ],
            "properties": {
                "publicAccess": "Container"
            }
        },
        {
            "type": "blobServices/containers",
            "apiVersion": "2018-03-01-preview",
            "name": "[concat('default/', parameters('Container2Name'))]",
            "dependsOn": [
                "[parameters('StorageAccountName')]"
            ],
            "properties": {
                "publicAccess": "None"
            }
        }
    ]
}
 

We can then go ahead and deploy this, and see the two containers being created. You can see in the template we are setting different Public Access properties on the two containers, you have a choice of 3 values here:

  • None (private container)
  • Container (the whole container is publically accessible)
  • Blob (only Blobs are publically accessible)

2018-11-11_17-49-37