5
votes

So now that it's (apparently) possible to create Blob Containers via an ARM template, is it possible to similarly create an Azure Storage Table? I've searched around but most of the answers are from before Blob Container creation was implemented and available.

I've also found the documentation for the REST API at https://docs.microsoft.com/en-us/rest/api/storageservices/create-table but I'm not sure if and how this maps to the JSON entry in an ARM template.

I'm looking to eliminate the PowerShell script that currently handles the creation of the Table resources in my deployment.

6

6 Answers

4
votes

As of the 2019-06-01 version ... Yes

No, this is not currently possible to do with an ARM template.

https://docs.microsoft.com/en-us/rest/api/storagerp/table/create
https://docs.microsoft.com/en-us/azure/templates/microsoft.storage/2019-06-01/storageaccounts/tableservices

{
  "name": "default",
  "type": "Microsoft.Storage/storageAccounts/tableServices",
  "apiVersion": "2019-06-01",
  "properties": {
    "cors": {
      "corsRules": [
        {
          "allowedOrigins": [
            "string"
          ],
          "allowedMethods": [
            "string"
          ],
          "maxAgeInSeconds": "integer",
          "exposedHeaders": [
            "string"
          ],
          "allowedHeaders": [
            "string"
          ]
        }
      ]
    }
  }
}

and tables:

{
  "name": "string",
  "type": "Microsoft.Storage/storageAccounts/tableServices/tables",
  "apiVersion": "2019-06-01"
}
3
votes

From 2019-06-01 is possible to create Table Services and Tables.

Table Services

   {
  "name": "default",
  "type": "Microsoft.Storage/storageAccounts/tableServices",
  "apiVersion": "2019-06-01",
  "properties": {
    "cors": {
      "corsRules": [
        {
          "allowedOrigins": [
            "string"
          ],
          "allowedMethods": [
            "string"
          ],
          "maxAgeInSeconds": "integer",
          "exposedHeaders": [
            "string"
          ],
          "allowedHeaders": [
            "string"
          ]
        }
      ]
    }
  },
  "resources": []
}

Tables

{
  "name": "string",
  "type": "Microsoft.Storage/storageAccounts/tableServices/tables",
  "apiVersion": "2019-06-01"
  }

See the references Azure Storage Account Table Services

2
votes

I would like to update this with an answer for anyone in the future trying to setup an ARM template with table service as the current documentation seems very vague in how these should be implemented. Specifically note the format of the names and that all items are defined as root level resources:

{
    "name": "[concat(parameters('storageAccount_name'),'/', parameters('tableServiceName'))]",
    "type": "Microsoft.Storage/storageAccounts/tableServices",
    "apiVersion": "2019-06-01",
    "properties": {
        "cors": {
            "corsRules": [
                {
                    "allowedOrigins": [
                        "*"
                    ],
                    "allowedMethods": [
                        "PUT",
                        "GET",
                        "POST"
                    ],
                    "maxAgeInSeconds": 0,
                    "exposedHeaders": [
                        "*"
                    ],
                    "allowedHeaders": [
                        "*"
                    ]
                }
            ]
        }
    },
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccount_name'))]"
    ],
    "resources": []
},
{
    "name": "[concat(parameters('storageAccount_name'),'/default/',parameters('table_name'))]",
    "type": "Microsoft.Storage/storageAccounts/tableServices/tables",
    "apiVersion": "2019-06-01",
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts/tableServices', parameters('storageAccount_name'), 'default')]",
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccount_name'))]"
    ]
}
1
votes

Sample ARM Template to create Blob and Table in a storage account

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "storageAccountName": {
        "type": "string",
        "metadata": {
          "description": "Specifies the name of the Azure Storage account."
        }
      },
      "containerName": {
        "type": "string",
        "defaultValue": "logs",
        "metadata": {
          "description": "Specifies the name of the blob container."
        }
      },
      "tableName": {
        "type": "string",
        "defaultValue": "logstable",
        "metadata": {
          "description": "Specifies the name of the table."
        }
      },
      "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
          "description": "Specifies the location in which the Azure Storage resources should be deployed."
        }
      }
    },
    "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2019-06-01",
        "name": "[parameters('storageAccountName')]",
        "location": "[parameters('location')]",
        "sku": {
          "name": "Standard_GRS",
          "tier": "Standard"
        },
        "kind": "StorageV2",
        "properties": {
          "accessTier": "Hot",
          "minimumTlsVersion": "TLS1_2",
          "allowBlobPublicAccess": false,
          "supportsHttpsTrafficOnly": true
        },
        "resources": [
          {
            "type": "blobServices/containers",
            "apiVersion": "2019-06-01",
            "name": "[concat('default/', parameters('containerName'))]",
            "dependsOn": [
              "[parameters('storageAccountName')]"
            ]
          },
          {
            "type": "tableServices/tables",
            "apiVersion": "2019-06-01",
            "name": "[concat('default/', parameters('tableName'))]",
            "dependsOn": [
              "[parameters('storageAccountName')]"
            ]
          }
          
        ]
      }
    ]
  }
0
votes

As of now only container is available. Microsoft are working on tables.

0
votes

You can use CreateIfNotExistsAsync method in your code

enter image description here In case your azure storage table does not yet exist it will create it. So you don't have to add things in the ARM templates.