Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Azure blob/fileshare container through ARM template

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
              }
        }
      }
    }
  }
like image 900
roy Avatar asked Dec 06 '16 20:12

roy


People also ask

How do I create a storage account in Azure using ARM template?

In a web browser, go to the Azure portal and sign in. From the Azure portal search bar, search for deploy a custom template and then select it from the available options. For Template source, notice that Quickstart template is selected by default.

Can we create container inside container in Azure blob storage?

There are no nested containers. Having said that, you can use slashes in your blob name to simulate nested containers in the URI.


2 Answers

It is possible. Azure Management REST Api now has endpoints for Blob Containers: https://docs.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"
          }
        }
      ]
    }
  ]
}
like image 177
clericc Avatar answered Oct 14 '22 06:10

clericc


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

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

like image 24
4c74356b41 Avatar answered Oct 14 '22 07:10

4c74356b41