Jonathan Claudio
Jonathan Claudio

Reputation: 63

Deploy Azure Table via Azure Resource Manager Template

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://learn.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.

Upvotes: 6

Views: 5033

Answers (6)

Dacili
Dacili

Reputation: 388

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.

Upvotes: 0

VIJAY RAAVI
VIJAY RAAVI

Reputation: 406

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')]"
            ]
          }
          
        ]
      }
    ]
  }

Upvotes: 3

Francois du Plessis
Francois du Plessis

Reputation: 2580

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'))]"
    ]
}

Upvotes: 4

4c74356b41
4c74356b41

Reputation: 72181

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

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

https://learn.microsoft.com/en-us/rest/api/storagerp/table/create
https://learn.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"
}

Upvotes: 5

Llazar
Llazar

Reputation: 3312

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

Upvotes: 3

Anish Shetty
Anish Shetty

Reputation: 63

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

Upvotes: 0

Related Questions