Did you know that it’s now possible to create blob containers under a Azure Storage Account via an Azure Resource Manager (ARM) Template?
Previously, only the creation of the storage account could be done via an ARM Template and the creation of the blob containers needed to be performed via an alternate way (e.g. via PowerShell) which makes it more complex to deploy the components from a pipeline or a single ARM Template.
In this short blog post I’ll show you how to create an Azure Storage Account and a blob container from a single ARM Template.
The “type” of the blob container in the ARM Template is “Microsoft.Storage/storageAccounts/blobServices/containers“. In the name of the blob container, note the “/default/” section which is required to properly create it: “[concat(parameters(‘storageAccount_name’),’/default/‘, parameters(‘storageContainer_name’))]”
As usual with storage accounts, they need to adhere a few naming conventions:
- Needs to be globally unique
- It must be between 3 to 24 characters long
- It can only contain lowercase letters and numbers
Also the blob containers need to adhere to a few naming conventions:
- It can only contain lowercase letters, numbers and hyphens
- It must begin with a letter or a number
- Each hyphen must be preceded and followed by a non-hyphen characters
- The name must be between 3 and 63 characters long
Taking the above into account, with below templates the Storage Account and Blob Container can be created.
The ARM Template used:
{ "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description": "Location for all resources, defaults to the resourcegroup location." } }, "storageAccount_name": { "type": "string", "metadata": { "description": "The storage account name" } }, "storageAccount_sku_name": { "type": "string", "allowedValues": [ "Standard_LRS", "Standard_GRS", "Standard_RAGRS", "Standard_ZRS", "Premium_LRS" ], "metadata": { "description": "One of the supported SKUs: Standard_LRS, Standard_GRS, Standard_RAGRS, Standard_ZRS, Premium_LRS" }, "defaultValue": "Standard_GRS" }, "storageAccount_access_tier": { "type": "string", "allowedValues": [ "Cool", "Hot" ], "metadata": { "description": "One of the supported tiers: Cool or Hot" }, "defaultValue": "Cool" }, "storageAccount_kind": { "type": "string", "allowedValues": [ "Storage", "StorageV2", "BlobStorage" ], "metadata": { "description": "One of the supported kinds: Storage, StorageV2, BlobStorage" }, "defaultValue": "StorageV2" }, "storageContainer_name": { "type": "string", "metadata": { "description": "Name of the storage container" } } }, "variables": {}, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "sku": { "name": "[parameters('storageAccount_sku_name')]" }, "kind": "[parameters('storageAccount_kind')]", "name": "[parameters('storageAccount_name')]", "apiVersion": "2017-10-01", "location": "[parameters('location')]", "tags": {}, "scale": null, "properties": { "networkAcls": { "bypass": "AzureServices", "virtualNetworkRules": [], "ipRules": [], "defaultAction": "Allow" }, "supportsHttpsTrafficOnly": false, "encryption": { "services": { "file": { "enabled": true }, "blob": { "enabled": true } }, "keySource": "Microsoft.Storage" }, "accessTier": "[parameters('storageAccount_access_tier')]" }, "dependsOn": [] }, { "name": "[concat(parameters('storageAccount_name'),'/default/', parameters('storageContainer_name'))]", "type": "Microsoft.Storage/storageAccounts/blobServices/containers", "apiVersion": "2018-07-01", "properties": { "publicAccess": "None" }, "dependsOn": [ "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccount_name'))]" ] } ] }
The ARM Template Parameters used:
{ "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "value": "westeurope" }, "storageAccount_name": { "value": "ktblogstorageaccount" }, "storageAccount_sku_name": { "value": "Standard_GRS" }, "storageAccount_access_tier": { "value": "Cool" }, "storageAccount_kind": { "value": "StorageV2" }, "storageContainer_name": { "value": "storagecontainerfromarm" } } }