5
votes

Is there's a way to create a Table inside Azure Storage Account using ARM template? I can achieve that using PowerShell but can't find a way to do it using JSON template, also when I browse my deployment resources using (https://resources.azure.com) I can't see any reference to the created table under the storage account, any idea why?

Thanks, A Seyam

3

3 Answers

3
votes
  1. As far as I know, no. You could look at Get started with Azure Table storage using .NET/PHP/Python/... for details.
  2. The Table service exposes Account, Tables, Entity via the REST API, so you couldn't see them in the portal. You can check out Addressing Table Service Resources for more info.
3
votes

You can create an Azure Storage account with a table via ARM like this, using a tableServices/tables sub-resource on your storageAccount resource:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountName": {
      "type": "string",
      "minLength": 3,
      "maxLength": 24
    },
    "storageAccountSku": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS"
      ]
    },
    "tableName": {
      "type": "string",
      "minLength": 3,
      "maxLength": 63
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageAccountName')]",
      "apiVersion": "2019-06-01",
      "location": "[resourceGroup().location]",
      "kind": "StorageV2",
      "sku": {
        "name": "[parameters('storageAccountSku')]"
      },
      "resources": [
        {
          "name": "[concat('default/', parameters('tableName'))]",
          "type": "tableServices/tables",
          "apiVersion": "2019-06-01",
          "dependsOn": [
            "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
          ]
        }
      ]
    }
  ]
}

The functionality is documented on the ARM Template spec page for tableServices/tables.

-1
votes

Creating Azure storage using ARM template with some easy steps. Please find the following steps to implement it.

Step 1: Open your powershell and login your account with Connect-AzureRmAccount

step 2: add your SubscriptionId Select-AzureRmSubscription -SubscriptionId <your SubscriptionId>

step 3: Create Resource Group New-AzureRmResourceGroup -Name yourResourceGroup -Location "South Central US"

Step 4: create azuredeploy.json and azuredeploy.parameters.json

azuredeploy.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "storageAccountName": {
        "type": "string",
        "metadata": {
            "description": "The name of the Azure Storage account."
        }
    },
    "containerName": {
        "type": "string",
        "defaultValue": "logs",
        "metadata": {
            "description": "The name of the blob container."
        }
    },
    "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
            "description": "The location in which the Azure Storage resources should be deployed."
        }
    }
},
"resources": [
    {
        "name": "[parameters('storageAccountName')]",
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2018-02-01",
        "location": "[parameters('location')]",
        "kind": "StorageV2",
        "sku": {
            "name": "Standard_LRS",
            "tier": "Standard"
        },
        "properties": {
            "accessTier": "Hot"
        },
        "resources": [
            {
                "name": "[concat('default/', parameters('containerName'))]",
                "type": "blobServices/containers",
                "apiVersion": "2018-03-01-preview",
                "dependsOn": [
                    "[parameters('storageAccountName')]"
                ]
            }
        ]
    }
]
}

azuredeploy.parameters.json

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "storageAccountName": {
        "value": "yourstorage"
    }
}
}

Step 5: run the following command

New-AzureRmResourceGroupDeployment -Name myDeployment -ResourceGroupName yourResourceGroup -TemplateFile <location>\azuredeploy.json -TemplateParameterFile <location>\azuredeploy.parameters.json

Step 6:

$saContext = (Get-AzureRmStorageAccount -ResourceGroupName yourResourceGroup -Name sitastoragee).Context 
New-AzureStorageTable –Name yourtablestorage –Context $saContext