15

I am looking a way to create a container in Azure blob & file-share storage through ARM template.

At present I have ARM template to provision the storage accounts, but I want to create containers also in ARM.

{
    "name": "[parameters('storageAccountName')]",
    "type": "Microsoft.Storage/storageAccounts",
    "location": "[resourceGroup().location]",
    "apiVersion": "[variables('storageApiVersion')]",
    "sku": {
        "name": "[variables('storageAccountType')]"
    },
    "dependsOn": [ ],
    "tags": {
      "Environment": "[parameters('Environment')]",
      "Project": "[parameters('ProjectName')]",
      "Contact": "[parameters('ContactName')]"
    },
    "kind": "Storage",
    "properties": {
      "encryption": {
        "keySource": "Microsoft.Storage",
        "services": {
              "blob": {
                "enabled": true
              }
        }
      }
    }
  }
David Makogon
  • 69,407
  • 21
  • 141
  • 189
roy
  • 6,344
  • 24
  • 92
  • 174

2 Answers2

12

It is possible. Azure Management REST Api now has endpoints for Blob Containers: https://learn.microsoft.com/en-us/rest/api/storagerp/blobcontainers/create.

Since ARM Templates map to REST requests, we can create the following Template, containing a Blob Container as a nested resource below the Storage Account. Of course, you can also describe the Blob container in the toplevel resource array, following the usual rules.

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {
    "accountName": "accountname",
    "containerName": "containername"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('accountName')]",
      "apiVersion": "2018-02-01",
      "location": "westeurope",
      "kind": "BlobStorage",
      "sku": {
        "name": "Standard_LRS",
        "tier": "Standard"
      },
      "tags": {},
      "dependsOn": [],
      "properties": {
        "accessTier": "Cool"
      },
      "resources": [
        {
          "type": "blobServices/containers",
          "apiVersion": "2018-03-01-preview",
          "name": "[concat('default/', variables('containerName'))]",
          "dependsOn": [
            "[variables('accountName')]"
          ],
          "properties": {
            "publicAccess": "None"
          }
        }
      ]
    }
  ]
}
clericc
  • 305
  • 2
  • 7
  • 1
    Concerning the concatenated name of the container: Resource Ids in azure consist of type-name-pairs. So, the Storage Account has a service 'blobServices'. There is only one blobService, called 'default'. And inside this blobService, there exist the type 'containers' and below that is the name of the container. So, the type consists of the type-path below the storage Account and the Name consists of the Name path. – clericc Jul 31 '18 at 08:08
  • Is it possible to create the containers in it's own copy job, ie not through nesting the container as a resource on the storage account? I can't get it to work. I get an incorrect segmenth length error and can't figure out the correct naming convention. – Molotch Sep 18 '18 at 14:56
  • 1
    Yes, type should then be Microsoft.Storage/storageAccounts/blobServices/containers, the name should be something like "/default/" – clericc Sep 20 '18 at 07:00
  • This doesn't work for me. Doesn't like the slash in the container name. 13:59:06 - 1:59:00 PM - Resource Microsoft.Storage/storageAccounts/blobServices/containers 'testcslstandard/default/testContainerName' failed with message '{ 13:59:06 - "error": { 13:59:06 - "code": "ContainerOperationFailure", 13:59:06 - "message": "The specifed resource name contains invalid characters}' – Geekn Jan 24 '19 at 21:01
  • 2
    @Geekn: https://learn.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata: "All letters in a container name must be lowercase." – clericc Jan 28 '19 at 08:48
  • @clericc So that worked for blob service (thanks for pointing that out). When I try to create a file share under the file service, it says HttpResourceNotFound (I used Microsoft.Storage/storageAccounts/fileServices/containers). What documentation did you see that gave you the name of the type (I probably have that wrong). – Geekn Jan 28 '19 at 21:37
  • file services are not manageable through management.azure.com afaik. At least the REST reference gives me nothing about fileservices. So you won't be getting here i'm afraid – clericc Jan 30 '19 at 09:03
11

No, you cant do that, consult this feedback item.

you can now create containers. https://stackoverflow.com/a/51608344/6067741

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • It wasn't possible before, but it is now. Check the answer of @clericc over here. Might be a good idea to revise this answer. – Jan_V Aug 09 '18 at 19:08
  • i have over 1000 answers on SO, you really expect me to regularly revise each one of them? you know you can just edit the answer. – 4c74356b41 Aug 09 '18 at 19:18
  • 1
    Oh sorry, didn't think of this. But I see you have already edited it already! – Jan_V Aug 09 '18 at 19:25