Create Azure blob/fileshare container through ARM template
Asked Answered
E

2

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
              }
        }
      }
    }
  }
Entomologize answered 6/12, 2016 at 20:59 Comment(0)
R
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"
          }
        }
      ]
    }
  ]
}
Ronnironnica answered 31/7, 2018 at 8:2 Comment(7)
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.Ronnironnica
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.Caesium
Yes, type should then be Microsoft.Storage/storageAccounts/blobServices/containers, the name should be something like "<storageAccName>/default/<containerName>"Ronnironnica
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}'Thereby
@Geekn: learn.microsoft.com/en-us/rest/api/storageservices/…: "All letters in a container name must be lowercase."Ronnironnica
@Ronnironnica 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).Thereby
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 afraidRonnironnica
B
11

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

you can now create containers. https://mcmap.net/q/773371/-create-azure-blob-fileshare-container-through-arm-template

Bischoff answered 6/12, 2016 at 21:0 Comment(3)
It wasn't possible before, but it is now. Check the answer of @Ronnironnica over here. Might be a good idea to revise this answer.Turnaround
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.Bischoff
Oh sorry, didn't think of this. But I see you have already edited it already!Turnaround

© 2022 - 2024 — McMap. All rights reserved.