Kevin's Azure blog

Sharing knowledge

Menu

Skip to content
  • Home
  • About
  • Contact

Category Archives: Storage Account

Creating Azure blob containers via ARM Template

Posted on 14 April 2019 by Kevin Timmerman

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:

  1. Needs to be globally unique
  2. It must be between 3 to 24 characters long
  3. It can only contain lowercase letters and numbers

Also the blob containers need to adhere to a few naming conventions:

  1. It can only contain lowercase letters, numbers and hyphens
  2. It must begin with a letter or a number
  3. Each hyphen must be preceded and followed by a non-hyphen characters
  4. 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"
        }
    }
}

Azure Portal result

Posted in ARM Template, Azure, Storage Account | Leave a comment

Recent Posts

  • Using values from your ARM template across your Azure DevOps Pipeline with PowerShell 19 May 2019
  • Creating Azure blob containers via ARM Template 14 April 2019
  • Develop and test Azure Stream Analytics in Visual Studio 17 March 2019
  • Session slides: Using ARM templates to deploy solutions on Azure 18 November 2018
  • I’ll be speaking at O365 Connect in Haarlem on Nov 15th 22 August 2018

Archives

  • May 2019
  • April 2019
  • March 2019
  • November 2018
  • August 2018
  • October 2017
  • August 2017
  • November 2016
  • August 2016
  • February 2015
  • December 2014
  • November 2014
  • October 2014

Categories

  • Apps
  • ARM Template
  • Azure
  • Azure DevOps
  • Conference
  • CSOM
  • Full Trust Code
  • Managed Metadata Service
  • Other
  • PowerShell
  • SharePoint 2010
  • SharePoint 2013
  • SharePoint Online
  • Storage Account
  • Stream Analytics
  • Surface Pro
  • Tips and Tricks
  • Visual Studio
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
Proudly powered by WordPress | Theme: Superhero by WordPress.com.